Wednesday, 9 September 2015

How to remove all classes using jQuery?

How to remove all classes using jQuery?


Question: How to remove class for single tag or single element with jQuery?
$(document).ready(function() {
    //Use this 
    $("#idName").removeAttr('className');

    //OR use this, both will be work same
    $("#idName").attr('class', '');
});

Any element having id="idName", Its class will be removed.
Element can p, div and p etc.
removeAttr is jQuery's inbuilt function, So you must call this function after loading the jQuery file.

$(document).ready() is used to identify jQuery file loaded.


Question: How to remove class for multiple tags in single line?
$(document).ready(function() {
    $(".className").removeAttr('className');
});

Any element having className class, "class" will be delete from html  tag.
Element can p, div & p etc.
removeAttr is jQuery's inbuilt function, So you must call this function after loading the jQuery file. $(document).ready();, is used to identify jQuery file loaded.


Question: How to remove class for single tag or single element without jQuery?
$(window).load(function() { 
    //Use this 
    document.getElementById('idName').className = '';
});

Any element having idName's class will be removed.
Element can pdiv and p etc.
$(window).load();, is used to identify html is fully loaded.


Tuesday, 8 September 2015

What are differences between $(document).ready and $(window).load?


What are differences between $(document).ready and $(window).load?

$(document).ready();
$(document).ready(function() {
 /** Add your code here **/
            


/** Add your code here **/

 console.log("HTML Document is fully load. HTML, javaScript and CSS is fully loaded.");
});

JavaScript code written inside $(document).ready will be called when HTML Document is fully loaded. It means JavaScript code will be called just after HTML, JavaScript & CSS is fully loaded.



$(window).load();
$(window).load(function() { 
 /** Add your code here **/
            


/** Add your code here **/


 console.log("Web page fully Loaded. HTML, Javascript, CSS, Images, Iframes and objects are fully loaded.");
});


JavaScript code written inside $(window).load will be called when Web page fully Loaded. It means JavaScript code will be called just after HTML, Javascript, CSS, Images, Iframes and objects are fully loaded.

Following document ready have same meaning and work as same.
$(document).ready(function(){

});
OR
$(function(){

});
OR
$(document).on('ready', function(){
})