July 8, 201214 yr So I just started learning Javascript and I might have a lot of questions about it. Please excuse me if I get annoying with my questions..I am just trying to understand how Javascript works. I'm learning from the W3School website just for anyone information. Okay let's get started! <!DOCTYPE html> <html> <body> <h1>My Web Page</h1> <p id="demo">A Paragraph.</p> <script type="text/javascript"> document.getElementById("demo").innerHTML="My First JavaScript"; </script> </body> </html> So basically the code above has Javascript using an ID named Demo. The ID is used to make a paragraph so that it can be incorporated into HTML is what I am guessing...However to make that work the... document.getElementById("demo") is what makes the ID work. Right? So, without that the code won't work right.
July 8, 201214 yr u need to add an event with it to make it work <script type="text/javascript"> function changeText(){ document.getElementById('boldStuff').innerHTML = 'Fred Flinstone'; } </script> <p>Welcome to the site <b id='boldStuff'>dude</b> </p> <input type='button' onclick='changeText()' value='Change Text'/> see here see here for some simple examples Edited July 8, 201214 yr by sash_oo7
July 8, 201214 yr Author I see now. Thank you! I am understanding a bit better. I was curious about the "boldstuff" though...I'm guessing that is how you make words bold?
July 8, 201214 yr you mean like this ? you can use <strong></strong>,<b></b>, or font-weight in css to make text bold Edited July 8, 201214 yr by sash_oo7
July 8, 201214 yr Author Yeah! Only in the code before the text was already bolded and didn't need to be shown by clicking the button.
July 8, 201214 yr If you want to learn JS, forget w3schools imo and do it with Codecademy. Much more fun. Goodluck, ~evu.
Create an account or sign in to comment