views:

47

answers:

3

Hi Folks,

I am working on a sample problem on jsFiddle at http://jsfiddle.net/Q9yHD/

I am trying to add a border to my table with code:

      $("#") + $id).find(".name").attr("border", "thick"); 

But it doesn't seem to be working. What am I doing wrong in here?

+4  A: 

If you want to set the border attribute of a <table> remove the extra ), here:

$("#") + $id).find(".name").attr("border", "thick"); 
     ^

To make it this:

$("#" + $id).find(".name").attr("border", "10"); 

Or if you're after CSS styling, you should use .css(), like this:

$("#" + $id).find(".name").css("border", "solid 10px #000"); 
Nick Craver
Hi Nick, Thanks for the reply. I tried:
t3ch
$("#" + $id).find(".table1").css("border", "solid 10px #000"); , but it isnt working.
t3ch
@t3ch - I'm not sure exactly what you're after, there's no `.table1` in your example though, is this what you mean? http://jsfiddle.net/nick_craver/Q9yHD/4/
Nick Craver
Hi Nick, I am sorry its not updating any changes I am making to it. but this is where I added the class table1 var $addTable = function() { return $('<table class="table1"><tr><td class="name"></td></tr></table>');}
t3ch
@t3ch - In that case the object wth the ID *is* the table, `.find()` looks *inside* which you don't need, just remove it like this: `$("#" + $id).css("border", "solid 10px #000");` You can test it here: http://jsfiddle.net/nick_craver/Q9yHD/8/
Nick Craver
Hi Nick, Thanks. Its working now.
t3ch
@t3ch - Welcome :) If it resolves your issue be sure to accept an answer to each of your questions :)
Nick Craver
A: 

Um, is that the exact code? Seems to be an extra close brace floating at the beginning:

$("#" + $id).find(".name").attr("border", "thick"); 
Rudu
Hi Rudi, I removed that extra bracket and its still now showing up.http://jsfiddle.net/Q9yHD/
t3ch
Had a peek at the code - can I ask what the point is? (Using jQuery to build over using plain HTML)
Rudu
Actually, we have to create a dynamic page based on the data supplied from the server.
t3ch
Then why not supply the HTML table fragment from the server - as it is you're assuming it'll be translated into a table, which is the same as hard-coding the table in the in the first place.
Rudu
Hi Rudi, thanks for the suggestion, I am going to send table fragment from the server now.
t3ch
A: 

Looking at the code. If you want to add a border only to a td with a class of 'name' then why not put that in the CSS portion and when you create the table and the eventual

<td class="name">name</td>

That thick style will be applied to it?

Jonathan Romanowski