I’m using jQuery 1.7.2
This line works fine on IE9, Chrome and Firefox:
$('.' + product.id + '#' + this).text("foo");
product.id being a string representing a class and this being a string representing an id.
The line is inside a $.each loop, I did not post the entire code of this function because it’s rather large and the error is located exactly on this line.
An example of a selector dynamically created with this loop would be:
$('.price#servicesPerMonth').text("foo");
In IE8 I get the following error:
Unexpected call to method or property access.
jquery-1.7.2.js, line 5847 character 5
The code in jQuery is this one:
append: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 ) {
this.appendChild( elem );
}
});
},
Line 5847 is this.appendChild( elem );
I think the problem is coming from concatenating the this variable in the jQuery selector, but I don’t really know an alternative to fix this.
Any suggestions?
Try using
or
It will be fine, notice the space before #