ahmedsaber111
ahmedsaber111

Reputation: 822

disable click that calls a javascript function

I have a simple menu with this structure:

<ul class="navigation">
  <li><a href="javascript:void(0)" onclick="javascript:dataTable()">Preview all record</a></li>
</ul>

In some cases in my project I need to disable calling dataTable() function when user clicking on this tag

I am using this

$('ul.navigation a').click(function(event){
     event.preventDefault();
});

but it doesn't work with me

Upvotes: 1

Views: 379

Answers (3)

XCS
XCS

Reputation: 28147

You can use a variable to store whether to call dataTable() or not:

onclick="javascript:if(showTable)dataTable()"

http://jsfiddle.net/shZFj/1/

Upvotes: 0

Ahmed Assaf
Ahmed Assaf

Reputation: 601

Try save the value and set the onclick attribute with nothing:

var tmpVal = $("ul.navigation a").attr("onclick");
 $("ul.navigation a").attr("onclick","");

And you can restore the value again :

$("ul.navigation a").attr("onclick",tmpVal );

Upvotes: 0

Fr&#233;d&#233;ric Hamidi
Fr&#233;d&#233;ric Hamidi

Reputation: 262939

Try removing the onclick HTML attributes instead:

$("ul.navigation a").removeAttr("onclick");

Upvotes: 3

Related Questions