I'm looking to create a jQuery script that will replace an html variable if and only if it is inside a certain div. I'd like it to do this for each PostID though.
Each variable is unique depending on the post id.
Example:
<div class="[PostID]">
<div class="special">
<div class="container">
(Variable 1 has been replaced by variable 2 here due to the Special class)
[Variable 2]
</div>
</div>
</div>
I created a quick script but the problem I have is that when the first variable 2 is replaced, that is also the variable that is used to replace the following special classes. They aren't using their own variable.
Sorry if this is confusing.
Thank you.
<script type="text/javascript"> $(document).ready(function() { $(".special .container").html($(".container").html().replace('[Variable1]','[Variable2]')); }); </script>Pretty new at jQuery so this is probably awfully coded. Yes @SmokeyPHP it is only replacing once, instead of for each post. I'm not sure how to add in the PostID and make it check for each PostID class..containerclass element appear in your HTML (it's not in your posted HTML). Will thespecialclass be consistent in relation to the changing[PostID]element and thedivs of classmain? What relation does the[PostID]have on the variables you're replacing? Please, show us your actual (representative) input to the script and the desired output from the script. And please, when showing code, edit your question to include code in the question, not in comments, where it's (more or less) illegible.