JQuery - Change the href of the li a 's to javascript:void(0) - Stack Overflow

I have a thumbnail list:<ul><li><a href=#c1><img ><p>1 Thumb<p>&l

I have a thumbnail list:

<ul>
  <li><a href=#c1><img /><p>1 Thumb</p></a></li>
  <li><a href=#c2><img /><p>2. Thumb</p></a></li>
  <li><a href=#c3><img /><p>3. Thumb</p></a></li>
</ul>

And javascript (i use jquery framework) should change every href of the a's in the ul to javascript:void(0)

It's like:

$("#thumbs ul li > a").href( 'javascript:void(0)');

I have a thumbnail list:

<ul>
  <li><a href=#c1><img /><p>1 Thumb</p></a></li>
  <li><a href=#c2><img /><p>2. Thumb</p></a></li>
  <li><a href=#c3><img /><p>3. Thumb</p></a></li>
</ul>

And javascript (i use jquery framework) should change every href of the a's in the ul to javascript:void(0)

It's like:

$("#thumbs ul li > a").href( 'javascript:void(0)');
Share Improve this question edited Oct 8, 2012 at 16:21 caitriona 9,1614 gold badges33 silver badges36 bronze badges asked Dec 16, 2010 at 10:34 TomkayTomkay 5,16021 gold badges65 silver badges94 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You can do what you want using .attr() (used for attributes, instead of .href()) like this:

$("#thumbs ul li > a").attr('href','javascript:void(0)');

...but I wouldn't, there's a better way to solve your problem, for example:

$("#thumbs ul li > a").click(function(e) {
  e.preventDefault();
});

This attaches a property click handler to prevent the navigation, rather than messing with attributes to do the same.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745231339a4617691.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信