#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    How to call external css id with JS?


    How do I reference an external .css id with JS?

    My .css is called: pmstyles.css
    My id I want to reference is: rarity-common

    Any help would be appreciated. Thanks.
  2. #2
  3. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,008
    Rep Power
    2791
    Welcome to DevShed.

    I'm not certain what you are asking exactly. You have a style sheet called "pmstyles.css" with a declaration of "#rarity-common".

    If you want to dynamically insert the style sheet into the document, you can use something like this.
    Javascript Code:
    function importCSS() {
    	var ss = document.createElement('link');
    	ss.type = 'text/css';
    	ss.rel = 'stylesheet';
    	ss.media = 'screen';
    	ss.href = 'pmstyles.css';
     
    	document.head.appendChild(ss);
    }
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0
    Sorry for the unclear explanation. I am brand new to CSS and Javascript.

    Basically I want to change the following text formatting HTML code from HTML to Javascript using CSS to define the font formatting.

    Code:
                      
    <p align="center">
    <font color="#ffffff" size=2 face=Tahoma><b>
    <script type="text/javascript">
    document.write(mini01[0])
    </script>	
    </b></font>
    I have defined all these elements under the pmstyles.css file under the id: #rarity-common

    I have also included at the top of my html doc:
    <link rel="stylesheet" type="text/css" href="pmstyles.css">

    What is the best way to do this... or is the code you provided the best way to do it?

    Thanks.
  6. #4
  7. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,008
    Rep Power
    2791
    No, the script I posted is not relevant.
    CSS Code:
    p#rarity-common {
    	text-align: center;
    	color: #ffffff;
    	font-family: Tahoma, sans-serif;
    	font-size: 0.82em;
    	font-weight: bold;
    }
    HTML4Strict Code:
    <p id="rarity-common">
    	<script type="text/javascript">
    		document.write(mini01[0]);
    	</script>
    </p>
    Last edited by Winters; November 6th, 2012 at 02:36 AM. Reason: typo
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.

IMN logo majestic logo threadwatch logo seochat tools logo