简体   繁体   中英

jQuery .text not working, but .val does?

I have the code working in jsfiddle but when i implement the code into my solution it does not do anything.

When checkboxes are checked the idea is that it populates a comma seperated list of all items that have been checked into a div. However this does not work, but it works for a textarea fine?

http://jsfiddle.net/uJcB7/166/

This is the line in question:

 $('#standardFitFeatures').text(allVals)

Then I give the div then ID:

<div id="standardFitFeatures"></div>

This wont work at all, I have to create a textarea and change .text to to val

Any idea why and how I can sort this as I need it to populate the div?

put

$('#cblistp input').click(updateTextArea);
 updateTextArea();

and

 $('#cblistStatic input').click(updateTextAreaW);
 updateTextAreaW();

inside $(document).ready() if you want a consistent behavior

it is highly likely that you are binding events to elements that don't yet exist.

EDIT

.val() works for TextArea and Input whereas .Text() works for DIV ... Please check if you are indeed using Div in the production code and not textarea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM