-1

So the following is in my DOM:

<div
    id="itemEditor"
    class="quoteItemEditorView partType_MATERIAL editMode selectorEnabled" 
    style="left: -1px; right: 0px; width: auto; min-width: 480px; display: block;"
>

I am able to retrieve the element and replace the 'left' value however this is proving difficult. I have tried doing this through jquery and javascript via following methods but it wont over ride.

$("#itemEditor").css('style','left','400px !important');

document.getElementById("itemEditor").style.left="400px !important";

$("#itemEditor").css('style','left','400px');

document.getElementById("itemEditor").style.left="400px";

Any suggestions

TimoStaudinger
  • 41,396
  • 16
  • 88
  • 94

4 Answers4

1

You should do it like this using jQuery's css() method:

$("#itemEditor").css('left','400px');

jQuery css() gets the value of a computed style property for the first element in the set of matched elements or set one or more CSS properties for every matched element.

Hope this helps!

Saumya Rastogi
  • 13,159
  • 5
  • 42
  • 45
1

Just use:

$("#itemEditor").css("left","400px");

No need for "style" and "!important".

Vaidas
  • 1,494
  • 14
  • 21
1

I'm not sure why Saumya's answer got upvotes because it won't work. You can't use !important with .css() and you don't need it anyway as jQuery's .css() function put the CSS inline. The following should suffice:

$("#itemEditor").css('left','400px');

And you should avoid using !important at all costs.

jsFiddle example

j08691
  • 204,283
  • 31
  • 260
  • 272
  • True this but just to note aside in a case [like this](https://jsfiddle.net/a3ruzgq9/1/) maybe someone wants to override an `!important` from the CSS. If it is really necessary and there is no other approach like add another class refer to this question http://stackoverflow.com/questions/2655925/how-to-apply-important-using-css – DaniP Nov 16 '16 at 14:41
  • 1
    @DaniP Yes, there are rare, fringe cases where the only option is to use `!important` and that's about the only time it should be used. – j08691 Nov 16 '16 at 14:44
0

You will probably need to set position to absolute/relative like that:

 document.getElementById("itemEditor").style.position="relative";