V Posted July 30, 2010 Share Posted July 30, 2010 I'm using the jquery html() function to add some text into a textarea but it doesn't work with inputs. The working js is, $('.edit').click(function() { var unique_id = $(this).attr("id"); //get unique ID from .edit link var some_text = $('.some_text'+unique_id+'').html(); //get html from class with id=unique_id $('.some_input'+unique_id+'').html(some_text); //add html to textarea with id=unique_id }); And the HTML.. I'm using unique numbers for each group to edit them individually. <a href="#" class="edit" id="1">Edit</a> <div class="some_text1">Content here</div> <textarea class="some_input1"></textarea> <a href="#" class="edit" id="2">Edit</a> <div class="some_text2">Content here</div> <textarea class="some_input2"></textarea> <a href="#" class="edit" id="3">Edit</a> <div class="some_text3">Content here</div> <textarea class="some_input3"></textarea> Everything above works fine with textarea but when I change it to "input type="text" no html is added into the input. For example, <input type="text" class="some_input3" /> Is there any way of passing html() to inputs? Link to comment https://forums.phpfreaks.com/topic/209312-jquery-html-for-inputs/ Share on other sites More sharing options...
trq Posted July 30, 2010 Share Posted July 30, 2010 Use val() instead of html(). Link to comment https://forums.phpfreaks.com/topic/209312-jquery-html-for-inputs/#findComment-1092974 Share on other sites More sharing options...
V Posted July 30, 2010 Author Share Posted July 30, 2010 Great! Thanks thorpe! Jquery is starting to make sense Link to comment https://forums.phpfreaks.com/topic/209312-jquery-html-for-inputs/#findComment-1093153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.