james_027 wrote:
hi,
I am trying to use the jQuery .after() function. I have something like
this ..
$('p').after('<p class="main"><a href="#">sample</a></p>');
I want to transform it into something like this to make the code much
easier to read
$('p').after('
<p class="main">
<a href="#">sample</a>
</p>
');
how can I achieve this?
Thanks
james
The + operator does string concatenation in JavScript:
$('p').after(
'<p class="main">' +
'<a href="#">sample</a>' +
'</p>'
);
Turned out that this is a little slow thus I tend to use a array.join()
if the string gets longer, which is known to be faster:
$('p').after([
'<p class="main">',
'<a href="#">sample</a>',
'</p>'
].join(''));
--Klaus