As a result of my question here:
Passing site properties with javascript
I’m using the code below to pass text from one div to another in any instance that the data-target is equal to some elements class on a page.
$('#sp').children().each(function() {
$($(this).data().target).html($(this).html());
});
However, I’m wondering if instead of passing text to an html element, if i could type text on the page that is equal to the data-target value – then have that text be replaced by the text in data target. For example:
<div id="sp" style="display:none;">
<span data-target=".busFullName">My Great Company</span>
</div>
<!-- On some page -->
<p>sp.busFullName has been around since 1920</p>
<!-- Rendered text would be -->
<p>My Great Company has been around since 1920</p>
This way I don’t have to create an extra tag every time i use a property created.
Any insight would be appreciated. Thanks.
I don’t think you should take this approach since it renders your code semantically meaningless and somewhat unintelligible if JavaScript isn’t available in the client environment. That being said here is how I would have gone about it:
Demo: http://jsfiddle.net/rpHB2/3/