.has()
In this chapter you will learn:
Syntax and Description
The .has() method constructs a new jQuery object from a subset of the matching elements.
.has(selector)
selector
is a string containing a
selector expression to match elements against.
Return value is the new jQuery object.
Consider a page with a nested list as follows:
<ul>/*from j ava 2 s . c om*/
<li>1</li>
<li>2
<ul>
<li>list item 2-a</li>
<li>list item 2-b</li>
</ul>
</li>
<li>3</li>
<li>4</li>
</ul>
The following code
$('li').has('ul').css('background-color', 'red');
marks item 2 to red.
Next chapter...
What you will learn in the next chapter:
- Syntax and Description for .hasClass() method
- How to check if an element has a certain class
- Verify the existence of a class just added
- How to combine hasClass methods to filter