0
  <h2 class="cs-text">Word Set 
    <span id="words"> 
    </span>
  </h2>

in js code:

            var spanWordSet = $("#words");
            var li_element = "<span class='char" + word[0] + "'>" + word[0] + "</span>";
            spanWordSet.appendTo(li_element);

But I'm not able to append any span tag to the span id=words. The idea is to append a bunch of letters as span tag to the span id="words" and then remove them as a whole after a while. Any help?

1
  • you mistake appendTo with append Commented Jan 17, 2015 at 9:10

2 Answers 2

1
spanWordSet.appendTo(li_element);

should be

$(li_element).appendTo(spanWordSet);

You have to use the jQuery selector, $().


var spanWordSet = $("#words");
var word = ['1'];
var li_element = "<span class='char" + word[0] + "'>" + word[0] + "</span>";
$(li_element).appendTo(spanWordSet);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2 class="cs-text">Word Set 
    <span id="words"> 
    </span>
  </h2>

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

Comments

1
spanWordSet.appendTo(li_element);

should be other way round

$(li_element).appendTo(spanWordSet);

Yet another way of doing is

spanWordSet.append(li_element);

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.