I have the code:
<div class="message">
<span>Menu 1</span><span>Menu 2</span>
</div>
Note: between the span tags don’t have spaces. If I use:
$('.message').append('<span>Menu 3</span>');
The append adds a space in the line. Is there any other way to put a tag without having to add space?
I need the jquery generates a code like this:
<div class="message">
<span>Menu 1</span><span>Menu 2</span><span>Menu 3</span>
</div>
Thank you.
This fixes the problem:
jQuery was appending your new item after the line break. Using
span:last-childwill select the last menu item and then using.after()will add the new item directly after it.Please note that this will not work if
.messageis currently empty. You would need to check for this and use your current code in that case to add the first element.See the result here: http://jsfiddle.net/ZbSCU/