Anyone has any idea whats the equivalent of.show() of jquery in javascript?
I have tried using document.getElementById and add / remove class that I named "show" // "hide" but that doesn't work very well I might have wrong attributes in those classes I am not sure..
the show class is :
.show{
position:relative;
display:block;
}
and the hide class is:
.hide{
position:absolute;
top:0px;
right:0px;
display:none;
}
I am pretty sure there is a better way of going so.
jQuery Effect show() Method The show() method shows the hidden, selected elements. Note: show() works on elements hidden with jQuery methods and display:none in CSS (but not visibility:hidden).
jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: To show hidden elements, look at the show() method.
The equivalent to $() or jQuery() in JavaScript is querySelector() or querySelectorAll() , which can be called with a CSS selector.
$(this) is a jQuery object and this is a pure DOM Element object. See this example: $(".test"). click(function(){ alert($(this). text()); //and alert(this.
document.getElementById('myElement').style.display = 'block'; // show
document.getElementById('myElement').style.display = 'none'; // hide
jQuery takes into account what the value of display
was before hiding. When you fire show()
, it returns it back to what that value was. And so, it's NOT just simply setting the element's display
property to block
and none
.
so basically:
function hide(){
//get previous display value
//store it in an internal cache. jQuery has an internal data storage
//hide element
}
function show(){
//get previous display value for that element
//apply to element to show it
}
.show()
The matched elements will be revealed immediately, with no animation. This is roughly equivalent to calling
.css('display', 'block')
, except that the display property is restored to whatever it was initially. If an element has a display value ofinline
, then is hidden and shown, it will once again be displayed inline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With