View Full Version : Applying CSS class to a file type input element using JavaScript

05-06-2009, 11:10 AM
Hi all,

I am trying to create an input element of type file using the javascript. I am able to create it but the problem i am facing is, i need to apply a CSS class to the control. Can some one let me know how to do the same.

I am pasting the code that i am using to create a control.

function AddUploadFile()
var newrow = document.getElementById("files_tbl").insertRow(document.getElementById("files_tbl").rows.length);
var td1 = newrow.insertCell(0);
var hiddenFile = document.createElement("input");

hiddenFile.id = "File" + document.getElementById("files_tbl").rows.length;
hiddenFile.name = "File" + document.getElementById("files_tbl").rows.length;
hiddenFile.type = "file";
hiddenFile.className = "uploadtool";
hiddenFile.runat = "server";

Thanks & Regards,
Arun :)

05-06-2009, 02:15 PM
use the below logic, it may help you :thumbsup:

var x = document.getElementsByTagName('input');
for (var i=0;i<x.length;i++)
x[i].className = 'file hidden';

Regards, MSS

05-06-2009, 02:17 PM
Look into this

and this