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
1 Answer
Reset to default 4You 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.