1

I am using jQuery to append an element such as:

var mytop=100;
$(this).appendTo('.container')
       .last()
       .wrap('<div class="action" style="top:' + mytop + 'px;"></div>');

Only mytop is a calculated number. Since the new element has the class action, it should later change the top by adding a class moveup, such as:

$('document').on('click', function(e){
   if($(e.target).hasClass('action')){
      $(this).addClass('moveup');
   }
});

with the CSS as:

.moveup{
   top:5px;
}

The problem is, the inline CSS of the appended <div> overrides the class's CSS. When this newly created item is clicked, it should have its top set at 5px.

How do I override the inline CSS with the Class's CSS?

Sablefoste
  • 4,032
  • 3
  • 37
  • 58

1 Answers1

5

Taken from https://css-tricks.com/snippets/css/style-override-technique/

The !important rule at the end of a value will override any other style declarations of that attribute, including inline styles.

p { 
    font-size: 24px !important; 
}
MarkP
  • 2,546
  • 5
  • 31
  • 48