Why does this code work:
$('div.error_container').html('<div class="error">No more foo allowed</div>');
But this code causes an error:
$('div.error_container').html('<div class="error">No more foo allowed<br /></div>');
I've tried putting the <br />
before and after the </div>
tag, same error. I've tried changing it from <br />
to <br>
. Chrome always says the following in the inspector:
Uncaught SyntaxError: Unexpected token ILLEGAL
You can use . after() to insert an element after each the selector matched, like this: $("#twitter_update_list span"). after("<br />");
A jQuery object is created from the array elements in the order they appeared in the array; unlike most other multi-element jQuery operations, the elements are not sorted in DOM order. Elements will be copied from the array as-is and won't be unwrapped if they're already jQuery collections.
The add() method adds elements to an existing group of elements. This method adds elements on the whole document, or just inside context elements if the context parameter is specified.
Try breaking it up into a chain:
var $div = $('<div class="error"></div>').html('No more foo allowed')
.append('<br />');
$('div.error_container').html($div);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With