quarks
quarks

Reputation: 35276

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?");
})

Upvotes: 0

Views: 182

Answers (3)

Jarvan
Jarvan

Reputation: 1210

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.

Upvotes: 1

SivaRajini
SivaRajini

Reputation: 7375

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

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

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

Upvotes: 4

Related Questions