Reputation: 5199
I have been trying to use the following jquery expression tonight. It looks as if this expression does not work.
$("#mt-message").html('<li class="' + messageLevel.toLowerCase() + '"><a href="#" target="_self">' + message + '</a></li>');
Instead I had to use something else which did work but which I would rather not use.
$('#mt-news')
.append(
$('<li>').append(
$('<a>').attr('class', messageLevel.toLowerCase())
.attr('href','#')
.attr('target','_self')
.append(message)
)
);
Can someone please help me with the first expression and why it does not work? If the first expression is not possible with the second expression if I use it multiple times do I have to first remove the #mt-news content before appending?
thanks
Upvotes: 0
Views: 48
Reputation: 3158
The first expression is fine, so one of two things could be happening:
1). The element with that ID does not exist on that page (Perhaps could be the case, since the ID's in the two examples are different --)
2). One of those variables is not defined..
Check your error log / console , and see what it says -
Upvotes: 1
Reputation: 10374
Try this:
$("#mt-message").html('<li class="' + messageLevel.toLowerCase() + '"><a href="#" target="_self">' + message + '</a></li>');
toLowerCase() method call was not closed in the original question you posted. The current version (that was edited by someone else) shows the correct call to toLowerCase()
though.
Upvotes: 1