سؤال

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