Reputation: 34064
Let say I have,
<a id="a123"></a>
Now I need to check whether $("a") selector contains $("#a123") element.
Upvotes: 2
Views: 111
Reputation: 69915
If you want to find whether a
has this a123
id then you can do it using is
method which returns true
if it matches the selector else returns false.
if($("a").is('#a123')){
//It is #a123
}
If you want to find if a
contains child with id a123
then use has
method which reduces the set of matched elements to those that have a descendant that matches the selector or DOM element..
if($("a").has('#a123').length > 0){
//It contains child with #a123
}
References:
is()
- http://api.jquery.com/is/has()
- http://api.jquery.com/has/Upvotes: 3
Reputation: 1175
You can use.attr("id") to pull back the value of the id. Then you can use an if statement to check if the value is what you expected.
Upvotes: 2