• Log in or sign up for an account here: https://www.sythe.org/login

[JavaScript] Access multiple HTML Elements in Javascript.

Anet390

Grand Master

$5 USD Donor New
Joined
Jun 3, 2010
Sythe Gold
291
Messages
2,223
Discord Verified
Cryptocurrency Discussion Participant
Paper Trading Competition Participant
[JavaScript] Access multiple HTML Elements in Javascript.
Example of accessing one (Changing Text Color to Green):
Code:
<html>
<body>
<FONT Color="green" id="green"></FONT>
<script language="javascript">
document.getElementById("green").innerHTML="Green Text";
</script>
</body>
</html>

But how would I go about adding two HTML commands to one Line of Text. For Example, If I wanted to change the size and the color of the text, how would i be able to call both elements on the text "Green Text". So, not only with "Green Text" be green, the font size will be changed as well. I am terrible at explaining programming problems I have, so if this is confusing, ask for me to explain in more detail.
 
[JavaScript] Access multiple HTML Elements in Javascript.
Font tags are still used? How horrid.

Vanilla JS
Code:
<div id="colourText"></div>

<script type="text/javascript">
	document.getElementById("colourText").innerHTML="Green Text";
	document.getElementById("colourText").style.fontSize="20";
</script>


jQuery (http://jquery.com/)
Code:
<div id="colourText"></div>

<script type="text/javascript">
	$('#colourText').css('font-size',20).text('Green Text');
</script>
 
Discord Verified
Cryptocurrency Discussion Participant
Paper Trading Competition Participant
[JavaScript] Access multiple HTML Elements in Javascript.
Thank you for this! Very much apprecited. And yes, I guess ppl still do -.-
 
[JavaScript] Access multiple HTML Elements in Javascript.
Pretty sure they are depreciated, I haven't seen a font tag in awhile xD

Font tags are still used? How horrid.

Vanilla JS
Code:
<div id="colourText"></div>

<script type="text/javascript">
    document.getElementById("colourText").innerHTML="Green Text";
    document.getElementById("colourText").style.fontSize="20";
</script>
jQuery (http://jquery.com/)
Code:
<div id="colourText"></div>

<script type="text/javascript">
    $('#colourText').css('font-size',20).text('Green Text');
</script>
 
Runescape Gamblingrunescape gambling
Back
Top