A Question on JS and Jquery

Anything that can be done in jQuery can be done with plain 'ol vanilla JavaScript. You will just have to write more code.

jQuery is like a collection of shortcuts that will save you a lot of time in having to write functions to do common tasks.

Sometimes there is only the vanilla way such as when redirecting the page.

Eg:

window.location = 'newpage.html';

// or

window.replace('newpage.html');

The do nearly the same thing, but they're so simple that there just isn't a jQuery function for this. I'm sure there's other functions like this that are not included in jQuery.

jQuery is awesome for getting data from or making changes to any or all elements matching either classes or ID attributes.

Something like the following would change the text of the link when clicked. This can be useful when many element share the same class. Or if you need to reference just a single element you can do it by its ID. You can also mix variables in where you reference the ID or class. Can be a big time saver. You're not avoiding JavaScript by using it, but you're saving a lot of time if you use it correctly.

var myVar = "2";

$('#button_'+myVar).on('click', function(){ $(this).html ('CLICK ON ID#'+myVar); });

$('#button_1').on('click', function(){ $(this).html ('CLICK ON ID#1'); });

$('.editButtons').on('click', function(){ $(this).html ('EDITING'); });

<a id="button_1" class="editButtons">EDIT</a>

<a id="button_2" class="editButtons">EDIT</a>

Best way to learn is to just build something and mess with the code. Search and read up at jQuery's site and over at StackOverflow. There's also many tutorials on the net for simple to advanced jQuery projects. Search, read, and pursue the knowledge you seek through trial and error. That's how I've learned. I've never read a single book about jQuery, JavaScript, PHP, MySQL, or HTML. I searched the net and tried to build something that pushed the limits of what I was capable of. I still do the same thing to this day. It the only way I'll learn. If I do use it, I'll never learn it.

Someday soon I will find out a good use for Node.js in a project so that I can learn Node and NPM. There's many technologies and there's only going to end up being more, so don't stop at JavaScript and jQuery. Good luck!

/r/learnjavascript Thread