jquery - trying to set the data value of submit button -
this question has answer here:
i've been having problems trying set data value of elment. have following:
<textarea class='pairing-comment' ></textarea> <input data-comment="" data-global-id="187" type="submit" id="pairing-comment-submit">
i'd update the data-comment value when user changes textarea (testing has shown reliable way done):
$('textarea.pairing-comment').on('keyup',function() { var com = $(this).val(); console.log("here in pairing-comment " + com); // works fine $('#pairing-comment-submit'). data('comment', com); // not writing data-comment elment });
what jquery syntax write want data-comment value?
thx
if want attribute data-comment
updated, have use
$('#pairing-comment-submit').attr('data-comment', com);
when use .data(), updates value internal data structure maintained jquery instead of changing attribute value
demo: fiddle
Comments
Post a Comment