最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Populate input field using jQuery - Stack Overflow

matteradmin7PV0评论

I have a span on my page containing text, on page load, is it possible to populate an input field with this inner html using jQuery?

I've tried to setup a fiddle with my attempt only its not working...

/

I have a span on my page containing text, on page load, is it possible to populate an input field with this inner html using jQuery?

I've tried to setup a fiddle with my attempt only its not working...

http://jsfiddle/tQkaZ/

Share Improve this question asked Apr 20, 2012 at 10:05 LiamLiam 9,86340 gold badges114 silver badges214 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

You just missed the . off your first class selector. Here's an updated working fiddle.

$('hiddenfield').val( //Missing .
    $('.prodheader').html()
);​

the way you tried is correct. you just forgot to add the dot[.] before class name

$('.hiddenfield').val(
    $('.prodheader').html()
);

http://jsfiddle/tQkaZ/5/

You just forgot the class symbol in the selector. Here's the fix:

http://jsfiddle/tQkaZ/2/

$('.hiddenfield').val(
    $('.prodheader').html()
);​
Post a comment

comment list (0)

  1. No comments so far