1

Just a quick little thing I'm obviously doing wrong:

theDiv.append('<input type="button" id='+id+ 'value='+value+'></input>');

Where id and value are variables that I assign to as strings. Why wouldn't this work? What's the quick work-around?

thanks.

2
  • Need a little more information to help. You're trying to append an empty string to a div element? Commented Jun 19, 2011 at 0:15
  • arg no, I just didnt format it... ill edit. it says: '<input type="button" id='+id+ 'value='+value+'></input>'. Stackoverflow took my html literally! lol. Commented Jun 19, 2011 at 0:16

3 Answers 3

2

You need a space between the id and the value attribute:

 // --------------------------------------v
.append('<input type="button" id="'+id+ '" value="'+value+'">');  

I also added double quotes around the attribute values, and removed the closing </input> tag.

This results in:

<input type="button" id="id" value="value">

...given "id" as the value of id, and "value" as the value of value.

The way you had it, the value of the id attribute, and the value attribute itself were merged, so if the value of id was "id", it would look like:

<input type="button" id=idvalue=value>
Sign up to request clarification or add additional context in comments.

Comments

2

It does work. You are just missing your quotation marks around the attributes:

theDiv.append('<input type="button" id="'+id+ '" value="'+value+'" />');

example:

http://jsfiddle.net/niklasvh/LqvyQ/

Comments

1

If I have id = 1 and value = 15 then this is what makes it to the page

<input type="button" id=1value=15></input>

When you should really have

<input type="button" id="1" value="15"></input>

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.