I have this JavaScript function:
function Test(isValid) {
var divStart = $get('divDateFrom');
var divEnd = $get('divDateTo');
var txtStartDate = divStart.firstChild;
var txtEndDate = divEnd.firstChild;
var isValidFromForecastStartDate;
txtEndDate.setAttribute('dateInRegionalFormat', txtEndDate.value);
}
This function is working fine in IE but I'm getting "txtEndDate.setattribute
is not a function" error in Firefox and Chrome.
I have this JavaScript function:
function Test(isValid) {
var divStart = $get('divDateFrom');
var divEnd = $get('divDateTo');
var txtStartDate = divStart.firstChild;
var txtEndDate = divEnd.firstChild;
var isValidFromForecastStartDate;
txtEndDate.setAttribute('dateInRegionalFormat', txtEndDate.value);
}
This function is working fine in IE but I'm getting "txtEndDate.setattribute
is not a function" error in Firefox and Chrome.
- SetAttribute should work, pls check whether you get correct object in "txtEndDate" – AmGates Commented Oct 29, 2013 at 6:12
- Can you post your whole code in Js fiddle pls – AmGates Commented Oct 29, 2013 at 6:12
3 Answers
Reset to default 32Use jquery.attr() like,
$(txtEndDate).attr('dateInRegionalFormat', txtEndDate.value);
Updated there may be multiple elements
so use [0]
for the first element
like,
txtEndDate[0].setAttribute('dateInRegionalFormat', txtEndDate.value);
You should first check whether the elements exists or not
before setting attribute
in it like,
if(txtEndDate.length)
{
txtEndDate.setAttribute('dateInRegionalFormat', txtEndDate.value);
}
You can do it by this way:
txtEndDate['dateInRegionalFormat'] = txtEndDate.value;
instead of old code:
txtEndDate.setAttribute('dateInRegionalFormat', txtEndDate.value);
I have faced the same kind of issue very recently. Try to get rid of ".value" part. It may work for you.
txtEndDate.setAttribute('dateInRegionalFormat', txtEndDate);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1737594751a3958322.html
评论列表(0条)