开发者

getting the value of a div in jquery?

开发者 https://www.devze.com 2023-02-01 15:52 出处:网络
i wanted to get the value of a hidden div in jquery i.e. <div id=\"text\">hello i am the value, you want</div>

i wanted to get the value of a hidden div in jquery i.e.

<div id="text">hello i am the value, you want</div>

and i want insert this value into a another div in jquery i.e.

$('#bio').html($value);

EDIT:

i forgot to mention that it had to be the text within the block div sorry i.e. its parent

<div class="block" id="status_13">
<div id="text">.......</div>
</div>

i.e.

$('.block').click(function(){
 $('开发者_如何转开发#bio').html($('$text').html());


If your #text element contains HTML you might want to do:

$('#bio').html($('#text').html());

If you are only concerned with the literal text of #text then you can do:

$('#bio').text($('#text').text());

Of course, if you want to store the text in a variable first, you can do so:

var textValue = $('#text').text();
$('#bio').text(textValue);

In regard to your later edit:

$('.block').bind('click', function() {
  var thisTextValue = $(this).children('.text').first().html();
  $('#bio').html(thisTextValue);
});

Notice that I assumed the child div is marked with a class and not an id. Based on your description, it sounds like you have multiple "block" elements which each contain a "text" element. If that is the case, then $('#text') will always return the first "text" element in the document; IDs are unique in the document.


Don't use $ for variables (like $value), just value

var value = $('#text').html();


Did you try

$('#bio').html($('#text').html());


I think this would work

//get the value from hidden field and store it in the variable 'valueYouWant'
var valueYouWant = $("#text").html();

//set it in other field
$("#bio").html(valueYouWant);

edit: More information can be found here

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号