Thomas
Thomas

Reputation: 34188

How to disable all hyperlink using jquery

I know how to disable one hyperlink at a time, so when user clicks on it then nothing will happen. Here is sample:

$('#myLink').click(function(e) {
    e.preventDefault();
    //do other stuff when a click happens
});

But now I have many hyperlink for my pager within li and div. It looks like:

<div id='pager'>
    <ul>
        <li>
            <a href='search.aspx?page=1'>1</a>
        </li>
        <li>
            <a href='search.aspx?page=2'>2</a>
        </li>
        <li>
            <a href='search.aspx?page=3'>3</a>
        </li>
        <li>
            <a href='search.aspx?page=4'>4</a>
        </li>
    </ul>
</div>    

I want to iterate in all hyperlink with in my div and enable/disable all through two routines. As a result when the user clicks then nothing will happen and no postback occurs. One routine will disable all and one routine will enable all hyperlink as before. How can this be achieved?

Upvotes: 1

Views: 2891

Answers (2)

j08691
j08691

Reputation: 207861

$('#pager a').click(function(e) {
e.preventDefault();
//do other stuff when a click happens
});

Upvotes: 3

machineghost
machineghost

Reputation: 35740

Just use a jQuery selector that grabs all of those A tags, like so:

$('#pager a').click(function(e) {
    e.preventDefault();
}

Upvotes: 2

Related Questions