admin管理员组

文章数量:1290105

I have inline style

<div class="handle" id="parent4" value="3" size="large" style="position: relative; top: 0px; left: 0px; z-index: 0; cursor: pointer;"></div>

i want remove the position relative style in tha above code using jquery

<div class="handle" id="parent4" value="3" size="large" style= top: 0px; left: 0px; z-index: 0; cursor: pointer;"></div>

I have inline style

<div class="handle" id="parent4" value="3" size="large" style="position: relative; top: 0px; left: 0px; z-index: 0; cursor: pointer;"></div>

i want remove the position relative style in tha above code using jquery

<div class="handle" id="parent4" value="3" size="large" style= top: 0px; left: 0px; z-index: 0; cursor: pointer;"></div>
Share Improve this question edited Jun 18, 2014 at 12:16 Sudharsan S asked Apr 17, 2014 at 8:33 Sudharsan SSudharsan S 15.4k4 gold badges34 silver badges51 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

Try to override the position with static,

$('#parent4').css('position','static');

since static is the default position for any div elements.

For removing style, you can use .css(stylename,'') syntax.So in your case use this:

$('#parent4').css('position','');

Set the position to static, that's the default value.

Here is the code to remove

(function($)
    {
        $.fn.removeStyle = function(style)
        {
            var search = new RegExp(style + '[^;]+;?', 'g');

            return this.each(function()
            {
                $(this).attr('style', function(i, style)
                {
                    return style.replace(search, '');
                });
            });
        };
    }(jQuery));

Using this mini plugin you can write in your JS file

$('#element').removeStyle('position');

本文标签: javascriptremove only position relative inline style using jqueryStack Overflow