HTML 5 is definitely the future of the web. So one must
learn how to work on the JavaScript with Html 5.This article gives you the just
introduction how to use JavaScript in html 5.
JavaScript moved a lot since Netscape livescript . So the Html . As you all now traditional JavaScript
have the DOM selector getElementById , getElementsByTagname,getElementsByClassname.
The HTML 5 provide javascript a new
function called queryselector .So what does this query Selector does ? Before
going into this lets see the syntax of
this function.
document.querrySelector(‘idname’);
Let’s see how its work?
If we have a HTML file like this.
<div><p id=’Australia’>Melbourne</p><p id=’US’>New York</p><p id=’Australia’>Sydney</p></div>
And now if you use function like document.querySelector(‘australia’).style.color
=’red’; in your JavaScript file it will change the color of only first element
with the id Australia to red. It means the Melbourne will turn into red and Sydney
will not any effect on it.
There is one more
function called document.querySelectorAll
. If you will use this function like document.querySelectorAll(‘Australia’).style.color
=’red’; it will turn all the elements associated with the Australia. It means it
will turn Melbourne as we Sydney into red.
0 comments:
Post a Comment
...