Reputation: 37464
This is the jQuery:
<script type="text/javascript">
$(document).ready(function(){
var relName;
$('.child').each(function() {
relName = $(this).attr('rel');
relName.replace('&','');
$(this).attr('rel', relName);
$(this).appendTo('#' + $(this).attr('rel'));
});
});
</script>
With this relevant HTML:
<div rel="MadDogs&EnglishmenHandpaintedfigurines" id="Figurines" class="category section child">
<h3 class="categoryTitle">Figurines</h3>
</div>
But for some reason, the replace has no effect whatsoever!
Upvotes: 1
Views: 303
Reputation: 97591
Here's a neat way to write it, using the callback version of basically every jQuery method:attr
$(document).ready(function() {
$('.child').attr('rel', function(i, relName) {
$(this).appendTo('#' + relName);
return relName.replace('&','');
});
});
Upvotes: 2
Reputation: 46047
It's not updating because you're not assigning the result to anything.
Try this instead:
$(this).attr('rel', relName.replace('&',''));
Upvotes: 2
Reputation: 30115
replace
returns string with replaced data. So you need to assign back to your variable.
relName = relName.replace('&','');
Upvotes: 8