I've got "Uncaught TypeError: Cannot read property '0' of null" on the console log note that the code I use is work great on jsfiddle but not in my blog
blog url
the JavaScript code
<script type="text/javascript">
//<![CDATA[[
$(document).ready(function(){
$('.widget-content').each(function(){
var hg = $(this).html(),
qsqs = hg.match(/[^[\]]+(?=])/g);
alert(qsqs[0]);
});
});
//]]>
</script>
I've got "Uncaught TypeError: Cannot read property '0' of null" on the console log note that the code I use is work great on jsfiddle but not in my blog
blog url
the JavaScript code
<script type="text/javascript">
//<![CDATA[[
$(document).ready(function(){
$('.widget-content').each(function(){
var hg = $(this).html(),
qsqs = hg.match(/[^[\]]+(?=])/g);
alert(qsqs[0]);
});
});
//]]>
</script>
Share
Improve this question
asked Mar 4, 2014 at 0:49
abdelabdel
1031 gold badge2 silver badges12 bronze badges
4
-
console.log(qsqs, hg);
– zerkms Commented Mar 4, 2014 at 0:49 - can you see what's happen after I add your code Blog – abdel Commented Mar 4, 2014 at 0:53
-
Yes, I see that you're making wrong assumptions. If you checked
console.log
for your blog code (or used a debugger) - you could see it as well. – zerkms Commented Mar 4, 2014 at 0:54 - @zerkms Thank you, I forgot to check if the code exist before I executing it. – abdel Commented Mar 4, 2014 at 0:59
1 Answer
Reset to default 1The problem is that you have another div with the class widget-content and it's causing the jquery selector to run in both.
Example
<div class="widget-content">
[2][Sport][Two]
</div>
<div class="widget-content">
.
</div>
Here's the Fiddle updated so you can see the error clearly: http://jsfiddle/679JJ/1/