Wesley Smith
Wesley Smith

Reputation: 19571

how do I add to to contents of a td with jquery?

Im trying to get the text in a td with an id of "warningLabel", add to the text, then put the new text in the td.

I tried:

$('#warningLabel').html($('#warningLabel').html()+ "Please enter a date.\n");

This doesnt work but it doesnt raise any errors in firebug either.

If it matters, "warningLabel" may have no text in it to begin with.

How should i be doing this?

Update


The td in question starts out hidden

More of my code:

$(function(){   

function fieldsEntered(){
var check = true;
if($('#date').val()==""){
    $('#warningLabel').html($('#warningLabel').html()+ "Please enter a date.\n");
    check = false;
}
if($('#warningLabel').html()!=""){
    $('#warningLabel').show();
}


 return check;

}

});

Upvotes: 0

Views: 38

Answers (1)

Optimus Prime
Optimus Prime

Reputation: 6907

Have you heard of .append()?

Just try,

$('#warningLabel').append("Please enter a date.<br>");

Here is a DEMO showing how it works.

Also try showing the td after you add content to your warningLabel.

Upvotes: 3

Related Questions