[jquery] Jquery, set value of td in a table?

I create dynamic a table with <tr> and <td> tags. One of the td tags gets the id "detailInfo". I have an onclick function on some button. I would like to set some value in the td "detailInfo" after pressing on the button.

So how can I set the value of the td with id "detailInfo" ?

This is the td:

<td id="detailInfo" rowspan="2" width="300px">picture detail</td>

This question is related to jquery

The answer is


use .html() along with selector to get/set HTML:

 $('#detailInfo').html('changed value');

You can try below code:

$("Your button id or class").live("click", function(){

    $('#detailInfo').html('set your value as you want');

});

Good Luck...


Try the code below :

$('#detailInfo').html('your value')


From:

it could be:

.html()

In an HTML document, .html() can be used to get the contents of any element.

.text()

Unlike the .html() method, .text() can be used in both XML and HTML documents. The result of the .text() method is a string containing the combined text of all matched elements.

.val()

The .val() method is primarily used to get the values of form elements such as input, select and textarea. When called on an empty collection, it returns undefined.


$("#button_id").click(function(){ $("#detailInfo").html("WHAT YOU WANT") })