www.webdeveloper.com
Results 1 to 3 of 3

Thread: Dynamically add CSS classes via JS - cross browser solution

  1. #1
    Join Date
    Mar 2012
    Location
    Austria
    Posts
    34

    Dynamically add CSS classes via JS - cross browser solution

    Hey!

    Does anyone of you know a good cross browser solution for dynamically adding CSS classes using javascript?

    I tried this one http://coding.binon.net/index.htm?dhtml/addstyle.htm
    but it doesn't work cross browser.

    It works fine in Firefox, Opera and Safari, but fails in IE and Chrome..

    Thanks in advance for your help!

  2. #2
    Join Date
    Mar 2012
    Posts
    202
    Code:
    element.className = "class1 class2 class3";
    This should work, no?

  3. #3
    Join Date
    Mar 2012
    Location
    Austria
    Posts
    34
    Quote Originally Posted by Gray1989 View Post
    Code:
    element.className = "class1 class2 class3";
    This should work, no?
    No, I mean creating the whole CSS class itself using Javascript

    for example:
    Code:
    .font_1 {
    	font-family: Arial;
    	font-size:20pt;
    }
    			
    .font_2 {
    	font-family: Arial;
    	font-size:25pt;
    }
    I get all this information from a file and I want to create the corresponding CSS class dynamically using Javascript in order to assign it to any HTML element using the class attribute.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles