jQuery – Has Attribute Selector [name]

This jQuery selector selects elements that have the specified attribute, with any value.

Source Code

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<h4 id="number1" number="even">Number - 6</h6>
<h4 id="number2" number="odd">Number - 5</h6>
<button>Click Here</button>

  
<script>
jQuery(&quot;button&quot;).click(function () {
	alert(jQuery("#number2").attr('number'));
});
</script>
</body>
</html>

Demo

Following example fetch the ‘number’ attribute and display it as an alert message.

Number – 6

Number – 5

,

No comments yet.

Leave a Reply