gregor
gregor

Reputation: 2141

Jquery toggle, if javascript is disabled take user to a page

I have a div that appears and disappears through the use of a jquery toggle. When yuo click a link the div appears or disappears.

Is there a way to make it so if javascript is disabled and a user clicks the link they are taken to a page instead?

Is there anything I should do when using a toggle to ensure it doesn't encounter problems?

Upvotes: 0

Views: 65

Answers (2)

WhatisSober
WhatisSober

Reputation: 988

You can use both href and onClick for this.

If the javascript is disabled, href fires up

else onClick!

For example:

<a href="gosomewhere.html" onclick="toggle(); return false;">Click to toggle</a>

Javascript:

 toggle = function() {
     // Your code here
     return false;
    }

Upvotes: 0

hiattp
hiattp

Reputation: 2336

Make the link take the user where you want them to go if js is disabled by default. Then use jQuery's preventDefault() on the click event (where you are probably defining your toggling behavior).

So the link should work on its own:

<a id="functioning-link" href="/js_disabled_page">Toggle my div</a>

Your jQuery should grab the click event to toggle your div, which will only work if jQuery/js is enabled:

$(function(){
  $("#functioning-link").click(function(e){
    e.preventDefault();
    $("div").toggle();
  });
});

Upvotes: 3

Related Questions