admin管理员组文章数量:1323716
Modifying a jQuery plugin, I have lines of code as follows:
var currentread = (self).find('.c'+a).html();
//currentread = currentread.toUpperCase();
$('#output').html(currentread);
With the middle line mented out, the code works fine. The contents of the div with the class 'c[1-n]' is displayed in #output. Unmenting the middle line to convert this to upper case, however, generates the error 'currentread is null' for that line.
I must be doing something stupid here, but this doesn't seem to make sense. Any idea?
Modifying a jQuery plugin, I have lines of code as follows:
var currentread = (self).find('.c'+a).html();
//currentread = currentread.toUpperCase();
$('#output').html(currentread);
With the middle line mented out, the code works fine. The contents of the div with the class 'c[1-n]' is displayed in #output. Unmenting the middle line to convert this to upper case, however, generates the error 'currentread is null' for that line.
I must be doing something stupid here, but this doesn't seem to make sense. Any idea?
Share Improve this question asked Dec 30, 2011 at 19:33 DanDan 1,1912 gold badges23 silver badges39 bronze badges 4-
3
Why are you converting html to upper case? Did you mean to use
text()
? – josh.trow Commented Dec 30, 2011 at 19:35 -
1
the variable cannot "bee null" when you call
.toUpperCase()
- it must have been null beforehand. – Alnitak Commented Dec 30, 2011 at 19:37 - Post you html too. jsfiddle – abuduba Commented Dec 30, 2011 at 19:40
- josh.trow: Ah, changing it out to text() did the trick. I did think it a bit odd that the original plugin author chose html() but honestly I'm new to jQuery so didn't know about text(). Thanks! – Dan Commented Dec 30, 2011 at 19:40
1 Answer
Reset to default 9Is is simply the case that currentread
is null? You could change it to:
currentread = (currentread || "").toUpperCase()
so that toUpperCase is always called on a string.
本文标签: jqueryJavaScript variable becomes null when toUpperCase() appliedStack Overflow
版权声明:本文标题:jquery - JavaScript variable becomes null when toUpperCase() applied - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742125864a2421936.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论