0

i am tyring to insert textboxes to create empty rows but i want first textbox should be of 50px only i am creating them onclick event of a button using DOM approach how to define the width with respect to following approach

j is a variable being handled somewhere & cols is no: of columns to be created

for(var t=1;t<=cols;t=t+1) { var cell = row.insertCell(t); var element = document.createElement("input"); element.type = "text"; element.id= 'text['+j+']['+(t)+']'; element.name= 'text['+j+']['+(t)+']'; element.value=""; cell.appendChild(element); } 
1
  • i tried following too but not worked if(t===1) { element.style.width="50px"; } Commented Apr 10, 2013 at 9:45

2 Answers 2

1

some times it may works

element.style.width = width + 'px'; 

try it once in case the above suggestions fails

or by using this,

element.setAttribute("style","width:50px"); 
Sign up to request clarification or add additional context in comments.

1 Comment

thnx... this worked element.setAttribute("style","width:50px");
0

Try the following:

In CSS:

.firsttext { width: 50px; } 

In Javascript:

if (t==1) { element.className = "firsttext"; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.