Adblock breaks this site

[JavaScript] Access multiple HTML Elements in Javascript.

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

  1. Anet390

    Anet390 Grand Master
    $5 USD Donor New

    Joined:
    Jun 3, 2010
    Posts:
    2,223
    Referrals:
    1
    Sythe Gold:
    291
    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.
     
  2. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    [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>
     
  3. Anet390

    Anet390 Grand Master
    $5 USD Donor New

    Joined:
    Jun 3, 2010
    Posts:
    2,223
    Referrals:
    1
    Sythe Gold:
    291
    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 -.-
     
  4. Ryan

    Ryan Hopeless Romantic
    Banned

    Joined:
    Mar 14, 2006
    Posts:
    2,946
    Referrals:
    31
    Sythe Gold:
    56
    [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 | >


 
 
Adblock breaks this site