Tuesday, December 20, 2016

Javascript-1-document.getElementById('') operations


References : w3schools.com
1)http://www.w3schools.com/jsref/default.asp
2)http://www.w3schools.com/js/default.asp

JavaScript is the programming language of HTML and the Web.

obfuscation Making code unreadable using advanced algorithms.


Change HTML element's content(.innerHTML)

The below code creates a button when clicked on it, the date is displayed in another element with  id="demo", when ie, it changes the element content

<button type="button" onclick="document.getElementById('demo').innerHTML = Date()">
</button>
<p id="demo"></p>

O/P: 







getElementById('demo') : to "find" an HTML element (with id="<<givenId>>") 
.innerHTML : changes/sets the element content

________________________

Change HTML attributes(.src)

The below code changes the src(source) attribute of an img .

<button onclick="document.getElementById('myImage').src='pic_bulbon.gif'"></button>
<img id="myImage" src="pic_bulboff.gif" style="width:100px">


________________________


Change HTML styles(CSS)(.style.) 

<p id="demo">JavaScript</p>
<button type="button" onclick="document.getElementById('demo').style.fontsize="25px">Click Me!</button>


Hide HTML element(CSS)(.style.display="none") 
<p id="demo">JavaScript</p>
<button type="button"  onclick="document.getElementById('demo').style.display="none">Click Me!</button>


Show/Display HTML element(CSS)(.style.display="block") 
<p id="demo">JavaScript</p>

<button type="button"  onclick="document.getElementById('demo').style.display="block">Click Me!</button>


________________________


2 comments:

  1. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
    python Training in Pune
    python Training in Chennai
    python Training in Bangalore

    ReplyDelete
  2. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
    Best Devops Training in pune
    Devops Training in Bangalore
    Power bi training in Chennai

    ReplyDelete