+ 2
How to use .getElementbyId("") in JS?
I am confused.
11 Réponses
+ 5
Anas Dharar
First set 'id' attribute to your desired element.
Example:
<div id='box'>Div</div>
Next, access element by it's id.
var box=document.getElementById('box');
And, work with it.
Example:
//changing innerHtml of div
box.innerHTML="Div Box";
//Now innerhtml of div was changed
https://www.sololearn.com/learn/JavaScript/2753/
+ 4
getElementById do not take the 's' as it return only one element...
ByClassName take the 's' as returning an array-like of possibly many elements ^^
+ 3
you have completed the css course, so you may be able to do it yourself: the only rule to be aware is the conversion of css kebab-case properties to js camelCase properties:
background-color => backgroundColor
+ 2
you forgot a 's' at Element end in function name ;)
+ 2
document.getElementsByClassName
+ 1
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
Thanks....Can I change the color of text with this??? If yes, please give the code
+ 1
Yes. You can change it with css style color property.
attach it in your Js.
box.style.color="red";
refer it.
https://www.sololearn.com/learn/JavaScript/2754/
+ 1
What is wrong in this?
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
https://code.sololearn.com/WVieANtzMX0g/?ref=app
+ 1
https://code.sololearn.com/WSee8LVQYHku/?ref=app
https://code.sololearn.com/W2AmQTsVh9Z7/?ref=app
0
Thanks a lot visph & ˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ .....can you give a few examples that change Css elements like font and alignment??
0
Thanks a lot ˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ & visph