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? Quote Link to comment Share on other sites More sharing options...
trq Posted July 30, 2010 Share Posted July 30, 2010 Use val() instead of html(). Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.