JAB
JAB

Reputation: 3616

How to dynamically set align property for td in javascript?

Here is my code, my question is in the comment:

function (align) {    
    var column = $(`'<td>'`);  
  // now i need syntax to set align property to this td element  
  // column.align = align (not working)  
}

As shown, column.align = align is not working.

Where am I going wrong?

Upvotes: 4

Views: 18484

Answers (5)

vishal_b
vishal_b

Reputation: 1

Try this, myTD.setAttribute("align", "right");

Upvotes: 0

krtek
krtek

Reputation: 26607

it seems you're using jQuery, so you can do something like :

column.attr('align', 'right');

Upvotes: 10

Sukhjeevan
Sukhjeevan

Reputation: 3156

Try this one:

$(column).attr("align","left");

Upvotes: 2

Aron Rotteveel
Aron Rotteveel

Reputation: 83203

Judging from the $ selector, you are using jQuery.

In that case, column is not a DOM element, but a jQuery selector result, and you have to treat it accordingly:

$(column).attr('align', 'left');

Upvotes: 0

user291545
user291545

Reputation:

Looks like you're using jQuery? Use column.attr('align', 'whatev') or better yet, use CSS.

Upvotes: 0

Related Questions