Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  17] [ 3]  / answers: 1 / hits: 15873  / 11 Years ago, sun, december 22, 2013, 12:00:00

I have the following HTML.



<ul class=static>
<li class=static dynamic-children>
<a class=static dynamic-children menu-item href=test.php tabindex=0>
<span class=additional-background>
<span class=menu-item-text>Link</span>
</span>
</a>
<ul class=dynamic>
</ul>
</li>
</ul>


As you can see when I click on Link then it takes me to test.php page. I want this Link to be unclickable like you place # for e.g. href=#



Is it possible to do this using CSS or Jquery? Can't use Javascript's document.getElementById because there is no ID defined for this element.


More From » jquery

 Answers
64

Different options:



$('a[href=test.php]').click(function(){
return false;
});


or



$(static dynamic-children a.menu-item).click(function(){
return false;
});


You can also use event.preventDefault() which prevents the default/expected behaviour of a link. Use like:



$(static dynamic-children a.menu-item).click(function(event){
event.preventDefault();
});

[#73602] Friday, December 20, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janettejordynm

Total Points: 550
Total Questions: 94
Total Answers: 98

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
janettejordynm questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Sat, May 23, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
;