Bug Tracker

Modify

Ticket #11173 (closed bug: wontfix)

Opened 17 months ago

Last modified 15 months ago

$(elem).css("property", "value !important") fails

Reported by: fam.lam Owned by:
Priority: low Milestone: None
Component: css Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

I'm not sure if this is a bug or intentional, but I guess it's a bug. In the FireFox (9.0.1, and maybe earlier versions too) and future webkit browser versions, the following code doesn't work

$("body").css("color", "red !important");

If you leave out the !important it works fine. See also:  http://jsfiddle.net/GGJHL/

It could be because jQuery calls style[ name ] = value; and these browsers do not support setting properties containing !important that way. The correct way to set it would be style.setProperty(name, value_without_!important, "important");

It would be great if jQuery could also support setting !important styles on browsers that support .setProperty().

Change History

comment:1 Changed 17 months ago by rwaldron

  • Priority changed from undecided to low
  • Resolution set to wontfix
  • Status changed from new to closed
  • Component changed from unfiled to css

It's smarter to avoid adding features to the core library and instead defer to the developer and allow them to create a class that can be used instead:

.importantRed {
  color: red !important;
}

$("body").addClass("importantRed");

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.