I have many div that sometimes contain links. I want to check if they have a link. This is my attempt:
var container = $(this).closest('.content').find('.text'); //Check if text contains a tags if(container+':has(a)'){ alert('contain link'); } else{ alert('no link found'); //Alert "contain link" even if no link is found. }
By executing container.html() , I see the exact content of the container , including anchor tags, but my code above will always say that it cannot find the anchor tag.
Can someone tell me what I am doing wrong?
javascript jquery dom html jquery-selectors
Lomse
source share