javascript - Check if an element contains a specific child element -


i have many divs contain links. want check whether or not have link. attempt:

var container = $(this).closest('.content').find('.text');      //check if text contains tags     if(container+':has(a)'){         alert('contain link');      }     else{         alert('no link found');  //alert "contain link" if no link found.     } 

by doing container.html() can see exact content of container including anchor tags, code above cannot find anchor tag.

could tell me doing wrong?

change this:

if(container.find("a").length){ ... 

container jquery object , .find() function of object finds elements within it. length greater 0 mean finds anchor tag , evaluate true.

edit:

also, explain why example isn't working. when container+':has(a)', doing string concatenation runs tostring() on object (converting "[object object]"). end string "[object object]:has(a)" evaluate true.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -