Javascript jQuery

Code Snippets jQuery


In this code snippet, we’ll learn about jQuery.

jQuery is a library that makes working with javascript a bit easier and quicker. It’s not as popular or needed these days because of all the js frameworks. But it’s still present on a lot of older code. Also, I think it’s useful if you are making a smaller project and don’t need the features and complexity of a js framework.

Note: There are lot more jQuery functions than demonstrated here. This is the complete documentation. Also, I demonstrate some of those functions in other posts.  

Adding jQuery

You can add it by using the <script> tag. The src can then be pointed to either a CDN(like in the example below) or to a jQuery file added to your project locally. jQuery download here

<script src=""></script>


let element;

//Get element by id.
element = jQuery("#someid");
//Get element by class.
element = jQuery(".someclass");
//Get element by tag.
element = jQuery("p");
//Remove element.
//Get perent element.
element = jQuery("#someid").parent;
//Show element.
jQuery("#someid").show(); //If a number in miliseconds is put in as a parameter to show()/hide()  
//Hide element.
//Setting CSS properties.
//Setting inner HTML.
jQuery("#someid").html("<p>Just some text.<p/>"); //Call html() without parameters to get the html instead.
//Setting inner text.
jQuery("#someid").text("Some other text."); //Call text() without parameters to get the text instead.

Leave a Reply

Your email address will not be published.

The following GDPR rules must be read and accepted:
This form collects your name, email and content so that we can keep track of the comments placed on the website. For more info check our privacy policy where you will get more info on where, how and why we store your data.

Advertisment ad adsense adlogger