简体   繁体   中英

How to add span element inside td element while using .html(value To show) in jquery

My aim is to append data using <span> element inside of <td> . But I have to use .html() in jquery used inside loop. Now I'm getting the result using this code as,

$("td", row).eq(2).html(dateval);

The result i'm getting is,

<td>XYZ</td>

But I needs, the result as,

<td><span>My calculated value</span>XYZ</td>

How to append this span element inside td using this .html method. Any suggestions welcomed!.

尝试:

.html('<span>My calculated value</span>' + dateval);

You can achieve this by concatenating a <span>My calculated value</span> string with your value dateval .

var calcVal = '<span>My calculated value</span>'+ dateval;
$("td", row).eq(2).html(calcVal);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM