I've created the code below to use with any post. It is added to the page and similar pages. Which is placed HTML for it and its function is to show hidden speech when pressed with changing the name of the button and vice versa, but it does not work properly.
HTML Code:
<h3 class="h1">
Event Name
</h3>
<p> Lorem, ipsum dolor sit amet consectetur adipisicing elit. Omnis itaque, perferendis
nesciunt eum quidem hic delectus,
<span id="dots" class="dots">...</span>
<span id="more" class="more">Lorem ipsum dolor sit amet consectetur
adipisicing elit. Repudiandae dolore </span>
<button type="button" class="btn btn-outline-light read " id="read">Read
more</button>
<!--Chang button-->
</p>
JQuery Code:
// Start read more button
$(document).ready(function() {
$('.read').click(function() {
if ($(this).hasClass('active')) {
$(this).html('Read more').removeClass('active');
$(this).prev('.more').slideUp("slow");
} else
$(this).html('Read Less').addClass('active');
$(this).prev('.more').slideDown("slow");
});
});
// start comment system
The second is to add one number to the button when pressed and subtract it from the other, but it works with only one post on the page and I want it to work with an infinite number of posts on the same page and all the pages on which its HTML is placed
HTML Code :
<div id="demo">
<button class="like">
<i class="fa fa-heart" aria-hidden="true" onclick="clicking();"> Like</i>
<span id="slike">0</span>
</button>
<button class="dislike">
<i class="fas fa-heart-broken" aria-hidden="true" class="dislikes"
onclick="clicking();"> Dislike</i>
<span id="dlike">0</span>
</button>
</div>
JQuery Code :
// Start like & unlike button
var counter = 0,
count = 0;
$(document).ready(function() {
$('.like').one('click', function clicking() {
counter += 1;
count -= 1;
$('#slike').text(counter);
$('#dlike').text(count);
});
var coun = 0,
counte = 0;
$('.dislike').one('click', function click() {
coun += 1;
counte -= 1;
$('#dlike').text(coun);
$('#slike').text(count);
});
// End like & unlike button
});