MaxRecursion
MaxRecursion

Reputation: 4893

Search element inside element jQuery

In my HTML page DOM what I want to achieve is there is <li> tag with id 'liPref' and I want to search if that 'lipref' element has some element whose id contains string 'dlpref' as its inner HTML.

I am not getting any idea how do I achieve that using jQuery selectors.

Upvotes: 0

Views: 83

Answers (3)

Felix
Felix

Reputation: 38102

You can try to use attribute contains *= selector:

if($("#liPref [id*='dlpref']").length) { 
   // Existed
}

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388316

Try to check whether the liPref element has a an element with id containing the given string

if($('#liPref').has('[id*=dlpref]').length){
   alert('foune')
}

.has(), attribute contains

Upvotes: 1

Milind Anantwar
Milind Anantwar

Reputation: 82241

Try this:

$("#liPref").find("[id*='dlpref']").each(function(){
//do something here
});

For getting length:

 $("#liPref").find("[id*='dlpref']").length;

attribute-contains-selector

Upvotes: 2

Related Questions