开发者

JQuery (!= ) for XPATH is not working correctly

开发者 https://www.devze.com 2023-02-05 01:34 出处:网络
<html> <head> <script type=\"text/javascript\" src=\"http://code.jquery.com/jquery-1.4.4.min.js\"></script>
<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号