I was not really sure how to title this, but I hope that the question itself will make the most sense.
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(var i=0; i<str.length; i++){
$("div[id^= " + str.charAt(i) + "]").wrapAll("<div id='" + str.charAt(i) + "'
class='alpha-content'></div>");
//$("'#" + str.charAt(i) + "'").append('<span class="letter-header">' +
// str.charAt(i) + '</span>');
$('#A').append('<span class="letter-header">' + str.charAt(i) + '</span>');
};
So I am trying to append the span element to my generated html in a for loop, but for some reason i keep getting errors. With out the added span class, my html looks something like this:
<div id="A" class="alpha-content">
<div id="someName" class="inner-content">
<a href="someName">someName</a>
</div>
</div>
What i am trying to do is add a <span class="header-letter"> inside the letter with the corresponding div id tag. For some reason I can grab the letter just fine when I have it hard coded like $('#A').append blah blah blah... But if I try doing it with the $("'#" + str.charAt(i) + "'").append i get an error saying this:
Uncaught Error: Syntax error, unrecognized expression: '#A'
I can't figure out where I went wrong... Any ideas?