0

i have one question. Can i set dynimacly class attributes to an element on page with jquery?

Codes Example:

html

 ...
 <div id="example">
    ...
 </div>
 <div id="example2">
    ...
 </div>
...

css

 #example{
      background-color:red;
 }

jquery - this is what i want to do

 // Its just example how it have to works but i need other way in jQuery
 $('#example').click(function(){
      var class = createClass();
      var color = $(this).css('background-color');
      class.css('background-color', color);
      $('#example2').addClass(class);
 });

It is crucial to make it in this way. Because jquery adds css attributes direct to an element in his HTML code, but i need create Class with attributes and give it to one element element and then i want remove in one row $('#example2').removeClass(class);

Thanks for any response.

user2899587
  • 189
  • 2
  • 3
  • 11

0 Answers0