Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery click event on anchor

Tags:

People also ask

Can we use click in anchor tag?

The click method is intended to be used with INPUT elements of type button, checkbox, radio, reset or submit. Gecko does not implement the click method on other elements that might be expected to respond to mouse–clicks such as links (A elements), nor will it necessarily fire the click event of other elements.

How do I know which anchor is clicked in jQuery?

click(function(e){ var id = e.target.id; alert(id); }); }); In this way, e. target is the element you have clicked on.

How hit an URL on a button click in jQuery?

Answer: Use the jQuery click() Method You can use the click() method to trigger a click on a link programmatically using jQuery.


Here's the snippet of html i have:

<div id="tag-cloud-widget">  
    <div class="content">  
        <a href="#" rel="1" class="cloud-element" data-tag-id="10" style="font-size: 12px; color: rgb(205, 236, 222); ">T1</a>  
        <a href="#" rel="1" class="cloud-element" data-tag-id="1" style="font-size: 12px; color: rgb(205, 236, 222); ">T2</a>  
        <a href="#" rel="1" class="cloud-element" data-tag-id="3" style="font-size: 12px; color: rgb(205, 236, 222); ">T3</a>  
    </div>
</div>

I'd like to set up a click handler to respond to the user's click on the anchor tags. Here's the test code:

$("#tag-cloud-widget .content a").click(function(e) {
    alert('clicked');  
    return false;  
});  

The click handler above does not get fired and neither does this:

$("#tag-cloud-widget .content .cloud-element").click(function(e) {  
    alert('clicked');  
    return false;  
});  

However,

$("#tag-cloud-widget .content").click(function(e) { ... });  

and

$("#tag-cloud-widget").click(function(e) { ... });  

do get fired!

What am I not seeing???