views:

36

answers:

3

Hi could some one show me how to do the following:

var regep = /margin-bottom:([^;]+); margin-left:0px; margin-right:0px; margin-top:([^;]+);/;
elementCSS = elementCSS.replace( regep , "margin-bottom:\\1; margin-left:auto; margin-right:auto; margin-top:\\2;");

\1 to = ([^;]+) (margin-bottom) and \2 to = ([^;]+) (margin-top)

?? Cant seem to figure it out..

Regards Phil

A: 

I think you need to try using the Javascript RegExp.

astander
+1  A: 

If you are trying to dynamically adjust the top and bottom margins, it would be easier to just manipulate the element's style attributes directly with

element.style.marginTop = x; 
element.style.marginBottom = y;
Tatu Ulmanen
A: 
var regep = /margin-bottom:([^;]+); margin-left:0px; margin-right:0px; margin-
top:([^;]+);/;
elementCSS = elementCSS.replace( regep , "margin-bottom:$1; margin-left:auto; margin-right:auto; margin-top:$2;");
Phil Jackson