Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
function resetTabs(){
    $("#content > div").hide(); //Hide all content
    $("#tabs a").attr("id",""); //Reset id's      
}

var myUrl = window.location.href; //get URL
var myUrlTab = myUrl.substring(myUrl.indexOf("#")); // For mywebsite.com/tabs.html#tab2, myUrlTab = #tab2     
var myUrlTabName = myUrlTab.substring(0,4); // For the above example, myUrlTabName = #tab

(function(){
    $("#content > div").hide(); // Initially hide all content
    $("#tabs li:first a").attr("id","current"); // Activate first tab
    $("#content > div:first").fadeIn(); // Show first tab content
    
    $("#tabs a").on("click",function(e) {
        e.preventDefault();
        if ($(this).attr("id") == "current"){ //detection for current tab
         return       
        }
        else{             
        resetTabs();
        $(this).attr("id","current"); // Activate this
        $($(this).attr('name')).fadeIn(); // Show content for current tab
        }
    });

    for (i = 1; i <= $("#tabs li").length; i++) {
      if (myUrlTab == myUrlTabName + i) {
          resetTabs();
          $("a[name='"+myUrlTab+"']").attr("id","current"); // Activate url tab
          $(myUrlTab).fadeIn(); // Show url tab content        
      }
    }
})()
Posted
Comments
Dominic Burford 9-Jul-15 7:43am    
JQuery is a framework that is implemented in Javascript, so they share the same syntax. Your subject line is confusing. You have posted JQuery code but then your subject states that JQuery has more advantages. Can you be more accurate. What is it exactly you are trying to achieve?
Member 11719500 9-Jul-15 7:49am    
I mentioned jQuery has more advantages because everyone is using jQuery for its program size. But my question is I want to convert above jQery code to Javascript.
Ben J. Boyle 9-Jul-15 10:38am    
No tools exist that i know of, but here's a tutorial that walks you through the conversion for a number of the more common constructs: http://code.tutsplus.com/tutorials/from-jquery-to-javascript-a-reference--net-23703

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900