Combustion007
Combustion007

Reputation: 474

Fallback and JavaScript concurrently. What is the right way?

I have done numerous searches and have come across tons of online threads regarding "if JavaScript is disabled". My question is a bit different and would appreciate any insight in this.

I am currently developing a modest site, I have been instructed to implement fallback just in case if Javascript is turned off. Currently, I am developing HTML5 with jQuery. Entire site is wired up to jQuery. Site navigation is jQuery driven which is fully functional. My question is that if lets say that I implement a simple fallback strategy on site navigation like this:

  <li><a href="http://www.yahoo.com" title="yahoo">YAHOO</a></li>

As you can see this fallback is pretty straight forward, user clicks the list item and heads out to YAHOO. And lets say if JavaScript is not disabled then my jQuery code is for example:

 $("nav li:nth-child(1)).bind('click', function()
  {
         //ACTION GOT TO YAHOO
         $("#xxx").animate({'top' : '300'}, "slow"};
  });

My question is that now I have jQuery and fallback both rigged up concurrently. Should there just not be one or the other? is it a valid practice to have both methods coded simultaneously? As you can see, with jQuery, there are animations. So if both methods fallback and jQuery are wired up then which one would take the priority?

Upvotes: 1

Views: 126

Answers (1)

Gareth Parker
Gareth Parker

Reputation: 5062

Your Javascript would run first. This is the correct way to develop. This is called "Progressive Enhancement", which is good practice. As you've guessed, it basically means that those who do have javascript see the animation, and THEN run the link, and those who don't just click the link. So basically the best practice for fallback is what you're doing, just code HTML to work without JS, and use JS to change that, or make it better

Edit: I could be wrong in which goes first, only way to know is to test it yourself ;) But in my experience it'll go first

Upvotes: 1

Related Questions