<a href="#" class="readmore">YOUR TEXT"</a>
テキストのどこかにポップインして問題が発生した場合に、自動でもっと読んだり読んだりしないように作成しようとしています。現在はほとんど機能していますが、いくつかの異なる readmore を開いてから readless をクリックすると、ページ上のすべての readless が閉じます。何か案は?すべてのコードはコメント付きで以下にあります。
// Auto Readmore with a link that has the readmore class
$(document).ready(function() {
// Show Read more link that is hidden by css
$('.readmore').show("fast");
// Loop through all .readmores
$('a.readmore').each(function(index) {
// Set the Node of the link
var currentreadmore = $(this);
// set the id to the index of the each
$(this).attr('id', 'readmore-' + index);
var node = currentreadmore[0];
if (node && node.nextSibling) {
// if not at the end of a paragraph remove the rest of the paragraph and append ...
var afternodecontent = node.nextSibling.nodeValue;
node.nextSibling.nodeValue = " ...";
}
// hide everything after the readmore link
$(this).parent().nextAll().hide();
// create click function to append the rest of the paragraph and show the content. Also hides the readmore button
$(this).click(function() {
// add the content back in
if (node && node.nextSibling) node.nextSibling.nodeValue = afternodecontent;
// hide the content
$(this).parent().nextAll().slideToggle("slow");
// hide the read more button
$(this).hide("slow");
// add the readless button
$(this).parent().nextAll().last().append('<p id="readless-' + index + '" class="readless-wrapper"><a href="#" class="readless">Read Less...</a></p>');
// hvea the readless button click work
$('.readless').click(function() {
// show the readmore info based off of the index of the button
$('#readmore-' + index).parent().nextAll().slideToggle("slow");
// show the read more
$('#readmore-' + index).show("slow");
// append the ... and hide the rest of the content
if (node && node.nextSibling) {
// if not at the end of a paragraph remove the rest of the paragraph and append ...
var afternodecontent = node.nextSibling.nodeValue;
node.nextSibling.nodeValue = " ...";
}
// remove the readless button
$('.readless-wrapper').remove();
// stop the href
return (false);
});
// stop the href from working
return (false);
}); // Close Click function
}); // Close Each Function
}); // Close document ready