Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery click & get value of attributes of a href

How can I access seq value in a href, when I click thye link?

/* Add a listner to Group buttons */
    $('a.preActNav').click(function() { 
        alert(this.seq)
    });   



    <li><a href="#preclose4" data-theme="a" data-icon="arrow-d" data-transition="none" seq='1' class="preActNav"  ID="preActNavA">A</a></li>
    <li><a href="#preclose4" data-theme="a" data-icon="arrow-d" data-transition="none" seq='2' class="preActNav"  ID="preActNavB">B</a></li>
like image 765
bob Avatar asked Jul 08 '11 14:07

bob


People also ask

What is click in jQuery?

jQuery click() MethodThe click event occurs when an element is clicked. The click() method triggers the click event, or attaches a function to run when a click event occurs.

How do you click something in jQuery?

To trigger the onclick function in jQuery, click() method is used. For example, on clicking a paragraph on a document, a click event will be triggered by the $(“p”). click() method. The user can attach a function to a click method whenever an event of a click occurs to run the function.

Is jQuery click deprecated?

click() shorthand is deprecated at jQuery 3 on() and . trigger() methods can set an event handler or generate an event for any event type, and should be used instead of the shortcut methods.

What is click () method?

The click() method simulates a mouse-click on an element. This method can be used to execute a click on an element as if the user manually clicked on it.


1 Answers

Like this:

alert($(this).attr('seq'));

Although it may be better to put seq as another data element:

<li><a href="#preclose4" data-theme="a" data-icon="arrow-d" data-transition="none" data-seq='1' class="preActNav"  ID="preActNavA">A</a></li>

So then you can do:

alert($(this).data('seq'));

like image 124
Naftali Avatar answered Sep 27 '22 23:09

Naftali