64

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> 
3
  • What do you mean with "set some value"? td tags doesn't have value. Are you trying to append some text? Commented Apr 11, 2014 at 13:09
  • Have you tried anything? Commented Apr 11, 2014 at 13:12
  • I mean the html value. Commented Dec 11, 2017 at 8:49

5 Answers 5

117

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

 $('#detailInfo').html('changed value'); 
Sign up to request clarification or add additional context in comments.

Comments

12

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.

1 Comment

val doesn't work for me (tho I'm using an old version of jQuery); text does.
3

You can try below code:

$("Your button id or class").live("click", function(){ $('#detailInfo').html('set your value as you want'); }); 

Good Luck...

Comments

2

Try the code below :

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

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.