jquery has() method


  Translation results:

has

英[həz] 美[hæz]  

v.Have (the third person singular of have); (in a kinship relationship) accept; take; Buy

jquery has() methodsyntax

Function: has() Reduces the set of matching elements to a subset that has descendants that match the specified selector or DOM element.

Syntax: .has(selector)

Parameters:

ParameterDescription
selector String value, containing the selector expression of the matching element.

Description: If a jQuery object representing a collection of DOM elements is given, the .has() method constructs a new one using a subset of matching elements. jQuery object. The selector used is used to detect the descendants of the matching element; if any descendant element matches the selector, that element will be included in the result.

jquery has() methodexample

<!DOCTYPE html>
<html>
<head>
  <style>
    .full { border: 1px solid red; }
  </style>
  <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
</head>

<body>
<ul><li>Does the UL contain an LI?</li></ul>

<script>
  $("ul").append("<li>" + ($("ul").has("li").length ? "Yes" : "No") + "</li>");
  $("ul").has("li").addClass("full");
</script>

</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance

Popular Recommendations

Home

Videos

Q&A