0
var f = a('<span class="customSelectInnerText" />');
var e = a('<span class="customSelect"><span class="customSelectInner"></span></span>').append(f);

results in:

<span class="customSelect>
   <span class="customSelectInner"></span>
   <span class="customSelectInnerText">Text</span>
</span>

instead of the desired:

<span class="customSelect>
   <span class="customSelectInner">
      <span class="customSelectInnerText">Text</span>
   </span>
</span>

3 Answers 3

2

If you want just to adjust your code, you need to append f to .customSelectInner, it can be done with find.

var f = a('<span class="customSelectInnerText" />');
var e = a('<span class="customSelect">' +
          '<span class="customSelectInner"></span></span>')
         .find('.customSelectInner')append(f);

Note that I would break that code so every element has it's own variable, it's a lot more readable and easier to maintain and debug.

Sign up to request clarification or add additional context in comments.

Comments

1

Your statement selects the outer most element. You have to select the inner child before appending the previous <span>. Change to:

var e = a('<span class="customSelect"><span class="customSelectInner"></span></span>')
            .children().append(f);

Comments

1
var f = a('<span class="customSelectInnerText" />');

var e = a('<span class="customSelect"><span class="customSelectInner"></span></span>');
$(".customSelectInner").append(f);

Comments

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.