Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Using javascript instead of regex


Fotiman - 2:39 pm on Oct 11, 2007 (gmt 0)


Sounds like you'd want something like this:

function replaceNodeWithAttrValue(newValue, refNode) {
var parent = refNode.parentNode;
parent.replaceChild(document.createTextNode(newValue), refNode);
}

It would help if you added id attributes to your nodes. For example:

<img alt="wigget" src="http://example.com/wigget/red-wigget.jpg" width="100" height="120" class="class1" id="redwigget">
<form id="formX">
<input type="hidden" name="amount" value="19.99">
</form>

Then you could do:

window.onload = function() {
var img = document.getElementById('redwigget');
replaceNodeWithAttrValue(img.src,img);
var frm = document.getElementById('formX');
replaceNodeWithAttrValue(frm['amount'].value, frm);
};

Note, I haven't tested any of this, and I'm not sure what context you're running it in (a web page?). Hope it helps though.


Thread source:: http://www.webmasterworld.com/javascript/3474575.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com