javascript - how to alter a portion of a value of an attribute -


i've got bit of tricky one. i'm trying alter portion of string assigned style. use js change 50% in 2 gradient clauses different values without having create entire string in js.

is there sort of regex exchange in conjunction setattribute?

<a class="item" id="bob" style=" background-image:-moz-linear-gradient(0deg, rgb(0, 255, 0) 0%, rgb(250, 250, 5) 50%, rgb(252, 3, 3) 100%); background-image:-webkit-linear-gradient(0deg, rgb(0, 255, 0) 0%, rgb(250, 250, 5) 50%, rgb(252, 3, 3) 100%); filter:progid:dximagetransform.microsoft.gradient(startcolorstr='#00ff00',endcolorstr='#fc0303',gradienttype=1);">mytext</a> 

argh!

var el = document.getelementbyid('bob'); el.setattribute('style', el.getattribute('style').replace('50%', '30%')); 

but better:

var el = document.getelementbyid('bob'); el.style.backgroundimage = el.style.backgroundimage.replace(/50%/g, '30%'); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -