JQuery (!= ) for XPATH is not working correctly
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("[href!='http://www.google.net']").hide();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p class="waqar">This is a paragraph.</p>
<p class="wr">This is another paragraph.</p>
<a href="http://www.google.net">google</a>
<a href="http://www.yahoo.com">yahoo</a>
<button>Click me</button>
</body>
</html>
When i run this code whol开发者_如何学Goe page goes blank. Please help
$("[href!='http://www.google.net']")
selects all items (tags), which "href" property is not equal to "http://www.google.net". For example, <body>
tag have no property "href" => its value is not equal to "http://www.google.net" => it should be hidden.
Try this:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("a[href!='http://www.google.net']").toggle();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p class="waqar">This is a paragraph.</p>
<p class="wr">This is another paragraph.</p>
<a href="http://www.google.net">google</a>
<a href="http://www.yahoo.com">yahoo</a>
<button>Click me</button>
</body>
</html>
精彩评论