Hide show any element on a HTML page is vary common thing for websites. For Hide and Show elements Jquery is the most common and reliable framework. But There is some performance issue by jquery, so Javascript is the best solution for Hide and show any element on a web page.
Sometimes JQuery isn't necessary; if this is the only thing you need to do on a page, the overhead of loading the library far outweighs the need to write concise JavaScript.
It seems that hide() , show() and jquery visibility methods in general are not a good option in terms of performance.
Hide an element by id in Javascript:
[code language="js"]
document.getElementById("id").style.display = "none";
[/code]
Hide an element by id in jquery:
[code language="js"]
$("#id").hide();
[/code]
Hide an element by class in javascript :
[code language="js"]
document.getElementsByClassName("class")[0].style.display = "none";
[/code]
[code language="js"]
$(".class").hide();
[/code]
Show an element by id in Javascript:
[code language="js"]
document.getElementById("id").style.display = "inline";
[/code]
Show an element by id in Jquery:
[code language="js"]
$("#id").show();
[/code]
Show an element by class in Javascript:
[code language="js"]
document.getElementsByClassName("class")[0].style.display = "inline";
[/code</pre>
Show an element by class in jquery:
<pre>[code language="js"]
$(".class").show();
[/code]
Hide / Show all classes on a page in javascript.
Sometimes JQuery isn't necessary; if this is the only thing you need to do on a page, the overhead of loading the library far outweighs the need to write concise JavaScript.
It seems that hide() , show() and jquery visibility methods in general are not a good option in terms of performance.
Hide an element by id in Javascript:
[code language="js"]
document.getElementById("id").style.display = "none";
[/code]
Hide an element by id in jquery:
[code language="js"]
$("#id").hide();
[/code]
Hide an element by class in javascript :
[code language="js"]
document.getElementsByClassName("class")[0].style.display = "none";
[/code]
Hide elements by class in jquery
[code language="js"]
$(".class").hide();
[/code]
Show an element by id in Javascript:
[code language="js"]
document.getElementById("id").style.display = "inline";
[/code]
Show an element by id in Jquery:
[code language="js"]
$("#id").show();
[/code]
Show an element by class in Javascript:
[code language="js"]
document.getElementsByClassName("class")[0].style.display = "inline";
[/code</pre>
Show an element by class in jquery:
<pre>[code language="js"]
$(".class").show();
[/code]
Hide / Show all classes on a page in javascript.
Comments
Post a Comment