Prototype.js: reset setStyle

Is there a way how the reset styles go back to what's in my CSS?

Example:

#foo {width: 50px; height: 50px; position: absolute; top: 150px; left: 250px;}


function moveFoo(newpostop, newposleft){
  $('foo').setStyle({top: newpostop+'px', left: newposleft+'px'});
}

Now that I am done with this, I would like to move foo back when it was. I know this can be hardcoded, but I need to do this with 25 different divs.

thank

+5
source share
4 answers

The installation style does not eliminate all elements of the CSS class. It only redefines those that have been changed. The actual style of the control is a combination of a CSS style and a custom style attribute style. To completely revert to a CSS style, simply remove the style attribute.

$('#foo').removeAttr('style');

EDIT:

Obviously this does not work. In the comments I was told that the following:

$('#foo').writeAttr('style', '');
+5

null - prototype.js

, $('foo').setStyle({top:null,left:null}), .

+6

Javascript-, :

$('foo').removeAttribute('style');  

style = ""

+1

, , .

, . , , , , .

, ,

- :

   var tempStyle = new Array();

    function moveFoo(newpostop, newposleft){
      tempStyle ["foo"] = new Array();
      tempStyle ["foo"]["top"] = newpostop;
      tempStyle ["foo"]["left"] = newposleft;

      $('foo').setStyle({top: newpostop+'px', left: newposleft+'px'});
    }

   function restoreFoo(){
      $('foo').setStyle({top: tempStyle ["foo"]["top"]+'px', left: tempStyle ["foo"]["left"]+'px'});
    }
0

All Articles