[jQuery] expand-refs
[jQuery] expand-refs
Hi,
I'm generating some code that looks like the snippet below. Embedded
within the html are some <xref> elements. I want to expand each one
according to the corresponding property of the defs object.
My naive attempt is as follows
function expand_refs () {
$("xref").each(function (i) {
$(this).replaceWith(defs[$(this).attr("ref")]);
});
}
...but this only replaces the first level (i.e. it doesn't expand the
"D2488" xref). Can anyone help out?
Cheers,
Andy
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<html>
<head>
<title>
</title>
<script type='text/javascript' src='/js/jquery.js'></script>
<script type='text/javascript' src='/js/openair.js'></script>
<script type='text/javascript'>defs = { A : "<div id=\\'A\
\'><xref ref=\\'D2488\\'></xref></div>" ,
D2488 : "<div id=\\'D2488\\'><span id=\\'S2489\\'>andy</span><xref
ref=\\'D2490\\'></xref></div>" ,
D2490 : "<div id=\\'D2490\\'><span id=\\'S2491\\'>chambers</span></
div>" };
</script>
<style type='text/css'></style>
</head>
<body>
<div id='banner'>
<h1>
</h1>
</div>
<div id='content'>
<div id='A'>
<xref ref='D2488'></xref>
</div>
</div>
</body>
</html>