Hi every body
I don't JavaScript language well. I want to know about visibility or disable html's controls on a web page. I have a web page and I want disable some controls and print my page and after that the controls back to preview condition.
Pleeeeeeeeeeeeeeas help me:sad:
Pretty much what you're asking is how to style elements with JavaScript?
Styling elements with JS is very similar to CSS.Heres an example for hiding an element with the id "hide_div".
eg CSS:
[HTML]#hide_div {
display: none;
}[/HTML]
eg JS:
[HTML]document.getElementById('hide_div').style.display = 'none';[/HTML]
Most the time you want to hide or display a div as a result of a user generated event.
In CSS you have the event, "hover". In JS its "onmouseover".
Eg:
eg CSS:
[HTML]#hide_div {
display: none;
}
/* show the div on hover (non-IE only if not an anchor) */
#hide_div:hover {
display: block;
}
[/HTML]
eg JS:
[HTML]
var element = document.getElementById('hide_div');
element.style.display = 'none';
element.onmouseover = function() {
element.display = 'block';
}
element.onmouseout = function() {
element.display = 'none';
}
[/HTML]
Even though you can use JavaScript to change the style of html elements , its ususally better to let CSS do the work of styling, and just use JavaScript to switch between different styles. You can do this by changing the className (css calles it "class") of the element you want to style.
Example:
If you want to hide an element, create a class for hidden elements with CSS.
[HTML]
.hidden {
display: none;
}
[/HTML]
Then when you want to hide an element, just change its class to "hidden" so that it adopts the styles in the "hidden" class.
[HTML]
// adopt the "hidden" class style when clicked
var el = document.getElementById('my_element_id');
el.onclick = function() {
el.className = 'hidden';
}
[/HTML]
or you can check if its already hidden, and show it if it is:
[HTML]
.hidden {
display: none;
}
.shown{
display: block;
}
[/HTML]
[HTML]
// adopt the "hidden" class style when clicked
var el = document.getElementById('my_element_id');
el.onclick = function() {
el.className = (el.className == 'hidden') ? 'shown' : 'hidden';
}
[/HTML]
Thats the same as:
[HTML]
// adopt the "hidden" class style when clicked
var el = document.getElementById('my_element_id');
el.onclick = function() {
if (el.className == 'hidden') {
el.className = 'shown';
} else {
el.className = 'hidden';
}
}
[/HTML]
hope that gets you started.
What you'll need to look at are:
The DOM - document object model
The DOM function: getElementById()
DOM CSS: http://www.howtocreate.co.uk/tutorials/javascript/domcss
DOM Events: http://www.howtocreate.co.uk/tutorials/javascript/domevents