Frage

I have this HTML code, that I can not edit manually :(

<div id="grid" style="width:1435px; position:absolute;"></div>

I need some JQuery function to catch that element, and change style width from 1435 to 1000px?

.width{
     width:1000px;
}

$('#grid').addclass('width');

Does not work, because inline style has priority of styling the element, is it possible to catch that value and change it, tried it with !important too, but no luck.

EXTRA QUESTION?

I got the correct answer, but i having little issues, it is possible to catch that 1435px, because it always change, and just short it for 50px?

ANSWER

var divWidthContent= $("#grid")[0].style.width;
$('#grid').css({"width" :  (parseInt( divWidthContent ) - 50 + "px")});
War es hilfreich?

Lösung

This is how you should do it

 $('#grid').css({"width" : "1000px"});

Andere Tipps

You can use css()

 $('#grid').css('width','1000px');

And Additionally, You don't need to prefix class with ., Just use class name

 $('#grid').addclass('width');
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top