view raw
UnKnown UnKnown - 6 months ago 33
jQuery Question

How check if a video-id exists inside the table or not

I have a table as shown below , I am trying to check if a video-id exists inside the table or not

<div class="portlet-body">
<table class="mytable1 table table-bordered table-hover" id="videosfromtagstable">
<tbody class="connectedSortable ui-sortable">
<tr class="existingvideos">
<tr video-id="6" class="newvideos" style="display: table-row;">
<td><a href="xxx" target="_blank">xxx.jpg</a></td>
<tr video-id="48" class="newvideos">
<td><a href="xxx" target="_blank">xxx.jpg</a></td>


I am checking it this way , this is working, but could you please let me know if this the correct and efficient procedure ??

var checkvalue = checkifVideoExists(48);


function checkifVideoExists(videoid)
var flag = false;
$('#videosfromtagstable > tbody > tr').each(function()
if ($(this).attr('video-id') == videoid)
flag = true;
return false;
return true;
return flag;


It's not efficient way. Better select element via it's attribute:

function checkifVideoExists (videoid) {
    return $('#videosfromtagstable [video-id="'+videoid+'"]').length > 0;