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")});
有帮助吗?

解决方案

This is how you should do it

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

其他提示

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');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top