开发者

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&开发者_如何学Pythongt;'`);  
  // 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?


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

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


Try this one:

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


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


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');


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜