简体   繁体   中英

Change text of td element

I've been trying to change a text of a td element however I am not able to make it work:

http://jsfiddle.net/9HkWH/

What could be wrong in that fiddle?

Actually this is just my first step to do my actual goal that is to prettify a date using:

http://timeago.yarp.com/

Updated:

Where I need to do:

$(function() {
   $('td[kind="date"]').html("Hello?");
})

There are multiple problems

  1. Your script has a syntactical error, the quotes are not properly escaped
  2. Your html is not valid, there is no opening/closing <table tags
  3. Selector p[kind=date] is invalid since there is no p element, a td has the attribute kind="date" .

So

$(function() {
   $('td[kind="date"]').html("test");
})

Demo: Fiddle

First,you write the wrong selector,there is not 'p' element,your should try

$("td[kind='date']").html("test");

Second,the quotation marks in selector should be single not double.

Last and most important,your html code missed 'table' tag,so the html will render as text not a table,that's why your selector will not work even you change the selector by other's advices.

Check this Demo ,it works fine.

Can you please refer the below code.

function changeText() {
    $("#demoTable td").each(function () {
       $(this).html().replace("8: Tap on APN and Enter <B>www</B>", "");
    }
}

Replace text inside td using jQuery

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