Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

jQuery to JavaScript how to convert code from more advance to more simple version - understand code

Helo Guys! I coming here to you with some tricky question, can someone help me convert my code, this code I used in website for have more good looking website, but I dont now how its looks like in clear JavaScript. I try understand and rewrite but I'm not able..

$(document).ready(function(){
    $("#home").click(function(){
        $("#ajax-change-here").load("home.txt");
        return false; 
    });
});

$(document).ready(function(){
    $("#offer").click(function(){
        $("#ajax-change-here").load("offer.txt");
        return false; 
    });
});

$(document).ready(function(){
    $("#about").click(function(){
        $("#ajax-change-here").load("about.txt");
        return false; 
    });
});

$(document).ready(function(){
    $("#contact").click(function(){
        $("#ajax-change-here").load("contact.txt");
        return false; 
    });
});

3 Answers

Steven Parker
Steven Parker
231,007 Points

It seems like you have the concept of jQuery backwards, using jQuery makes your code more simple than doing everything in plain JavaScript. And this is especially true when doing AJAX functions. though the new "fetch" function is also pretty simple to use.

And whether you use jQuery or not, the "look" of your website will be the same. Changing how the code does the job will not improve the appearance to the user.

I understand what you mean, thanks.

My question is how same code will looks without jQuery? Anyway...

And can someone help me create function taking two arguments for reduce number lines of code..

Steven Parker
Steven Parker
231,007 Points

Which function do you mean? The ones shown here don't take any arguments.

We have there 4 times same code, code have change only in two places, so maybe we are able to create some function? Or not? I dont know, im really newbie..