[JavaScript] Access multiple HTML Elements in Javascript.

Discussion in 'Web Programming' started by Anet390, Sep 12, 2012.

[JavaScript] Access multiple HTML Elements in Javascript.
  1. Unread #1 - Sep 12, 2012 at 7:47 PM
  2. Anet390
    Joined:
    Jun 3, 2010
    Posts:
    2,223
    Referrals:
    1
    Sythe Gold:
    291
    Cryptocurrency Discussion Participant Paper Trading Competition Participant

    Anet390 Grand Master
    $5 USD Donor New

    [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.
     
  3. Unread #2 - Sep 12, 2012 at 10:50 PM
  4. Jazz00006
    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0

    Jazz00006 Apprentice
    Visual Basic Programmers

    [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>
     
  5. Unread #3 - Sep 12, 2012 at 11:05 PM
  6. Anet390
    Joined:
    Jun 3, 2010
    Posts:
    2,223
    Referrals:
    1
    Sythe Gold:
    291
    Cryptocurrency Discussion Participant Paper Trading Competition Participant

    Anet390 Grand Master
    $5 USD Donor New

    [JavaScript] Access multiple HTML Elements in Javascript.

    Thank you for this! Very much apprecited. And yes, I guess ppl still do -.-
     
  7. Unread #4 - Sep 26, 2012 at 9:34 AM
  8. Ryan
    Joined:
    Mar 14, 2006
    Posts:
    2,946
    Referrals:
    31
    Sythe Gold:
    56

    Ryan Hopeless Romantic
    Banned

    [JavaScript] Access multiple HTML Elements in Javascript.

    Pretty sure they are depreciated, I haven't seen a font tag in awhile xD

     
< CSS3 + jQuery download buttons | >

Users viewing this thread
1 guest


 
 
Adblock breaks this site