jQuery – Attribute Not Equal Selector [name!="value"]

The jQuery selector select elements that either don’t have the specified attribute, or do have the specified attribute but not with a certain value.

Source Code

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
<h6 attr="en">Div 1 (select this)</h6>
<h6 attr="en-US">Div 2 (select this)</h6>
<h6 attr="english">Div 3 (not selected)</h6>
<button>Click Here</button>

  
<script>
jQuery("button").click(function () {
	jQuery('h6[attr!="english"]').css("border","2px solid #1E8CBE");
});
</script>
</body>
</html>

Demo

Following example finds all DIV that don’t have the name ‘english’ and create a border around them.

Div 1 (select this)
Div 2 (select this)
Div 3 (not selected)

,

No comments yet.

Leave a Reply