3

I have this example

$('span.first').append('<span class="second">2</span>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="first">1</span> HELLO

I get this output: 12 HELLO

I need this output: 1 HELLO 2

2
  • 1
    Please always include the relevant code in the question itself as I just did. The question should be self-contained and include all the relevant details without external links to the code Commented Nov 11, 2020 at 9:23
  • 1
    Note that @AlonEitan has done you a favour there - must people would vote close your question. The message when saving the question is there for a reason Commented Nov 11, 2020 at 9:40

1 Answer 1

1

Your code was putting the 2 as a child to the span element hence why it was displaying as 12. For the result you are after, simply append to the parent of that element instead:

$('span.first').parent().append('<span class="second">2</span>');
Sign up to request clarification or add additional context in comments.

1 Comment

Working. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.