Jump to content

getElementByID etc.


EpicJS

Recommended Posts

If you have an element in your html such as...

<div id="mydiv01">To whom it may concern.</div>

...then you can write Javascript to change what is inside that element...

document.getElementById('mydiv01').innerHTML = '<b>Fore score and seven years</b>';

...the element is identified by the id. However note that not all elements have an innerHTML region.

Link to comment
Share on other sites

To add to davej's post, the id attribute basically allows you to set an "identifier" for a particular html element. It's a way to allow you to target an html element when necessary like with JavaScript(getElementById) and CSS. There can only be one id of the same name per webpage.

 

When you get an element by ID with getElementById, you now have access to that particular element and can manipulate that element like setting it's innerHTML or setting a className to it... or accessing the 'style' for that element and then change some of the styling for that element, like font color, background color, display, etc.

Link to comment
Share on other sites

are you having trouble following along with the tutorials? It seems you are asking very basic questions that are covered in the HTML / CSS / JS w3schools tutorials

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...