0

I am new to jQuery and I have an html file with this div element.

<div id="test div">Test Text</div>

and this div element.

<div id="dump contents"></div>

In my javascript file, I have this:

var testvariable = $("#test div").text();
$("#dump contents").html(testvariable);

But no matter what I do, nothing happens :(

Any advice? Thanks in advance!

2
  • 2
    You should not use space character in IDs. Commented Jan 2, 2013 at 22:29
  • 1
    IDs with spaces are invalid. And spaces inside a selector constitute the descendant selector: api.jquery.com/descendant-selector. Commented Jan 2, 2013 at 22:35

1 Answer 1

8

the id attribute should be without spaces

<div id="test-div">Test Text</div>

and

<div id="dump-contents"></div>

JavaScript:

var testvariable = $("#test-div").text();
$("#dump-contents").html(testvariable);

from w3.org

The id attribute specifies its element's unique identifier (ID). The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.

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

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.