I am new to JavaScript and jQuery.
Here is the HTML:
Code: Select all
<section>
<h2></h2>
<section></section>
<a href="">View</a>
</section>Code: Select all
$(document).ready(function(){
$('.content').click(function(){
url = $(this).attr('href');
content = $(this).prev().html();
if(content === '') {
$(this).prev().load(url,function(){
$(this).slideDown(400);
$(this).next().html('Close');
});
} else {
$(this).prev().slideUp(400,function(){
$(this).html('');
});
}
if($(this).html() === 'View') {
$(this).html('<img src="img/loading.gif">');
} else {
$(this).html('View');
}
return false;
});
$('.close').click(function(){
$(this).prev().slideUp(400,function(){
$(this).html('');
});
$(this).html('View').attr('class','button content');
return false;
});
});It works fine in every browser except IE8 and below where it shows the loading gif and and says there is an error in the script and never loads/shows the data.
How can I fix it?
Also if you have any suggestions on how to clean up the code, that would be great.
Thanks.