i have this 5 auto generated button from jquery and when you hover the button the image opacity filter changes:
but just the first button has the successful running function all of the others don’t.
how could I make the other generated buttons has the same effect too?
here’s my attempt:
$(document).ready(function(){
var maxLength = 120;
$(".show-read-more").each(function(){
var myStr = $(this).text();
if($.trim(myStr).length > maxLength){
var newStr = myStr.substring(0, maxLength);
var removedStr = myStr.substring(maxLength, $.trim(myStr).length);
$(this).empty().html(newStr);
$(this).append('<center><button class="btnsvc" id="wwdimg" style="top:20px" href="#!">Learn More</button></center>');
}
});
$('#wwdimg').mouseover(function(){
$('#img_holder').css({"opacity": "1","filter":"brightness(30%)"});
});
$('#wwdimg').mouseout(function(){
$('#img_holder').css({"opacity": "1","filter":"brightness(100%)"});
});
$('#wwdimg').mouseover(function(){
$('#img_holder').css({"opacity": "1","filter":"brightness(30%)"});
});
$('#wwdimg').mouseout(function(){
$('#img_holder').css({"opacity": "1","filter":"brightness(100%)"});
});
});
<div class="content back"></div>
<div id="img-hover" >
<img id="img_holder" src="http://192.168.1.250/sopi2018/wp-content/uploads/2018/03/h_backoffice-300x300.jpg" alt="" width="300" height="300" class="alignnone size-medium wp-image-604" />
</div>
<div class="show-read-more">Content and Creative Writing, Social Media Management, SEO, Outbound Sales, Outbound Sales Appointment Setting, Inbound sales, Surveys, Vendor Management and Support, Virtual Assistants
</div>
<div class="show-read-more">Content and Creative Writing, Social Media Management, SEO, Outbound Sales, Outbound Sales Appointment Setting, Inbound sales, Surveys, Vendor Management and Support, Virtual Assistants
</div>
<div class="show-read-more">Content and Creative Writing, Social Media Management, SEO, Outbound Sales, Outbound Sales Appointment Setting, Inbound sales, Surveys, Vendor Management and Support, Virtual Assistants
</div>
<div class="show-read-more">Content and Creative Writing, Social Media Management, SEO, Outbound Sales, Outbound Sales Appointment Setting, Inbound sales, Surveys, Vendor Management and Support, Virtual Assistants
</div>
<div class="show-read-more">Content and Creative Writing, Social Media Management, SEO, Outbound Sales, Outbound Sales Appointment Setting, Inbound sales, Surveys, Vendor Management and Support, Virtual Assistants
</div>
Working Fiddle: https://jsfiddle.net/akaqoaz0/37/
2
Answers
you are using the same id, id needs to be unique. so i changed it to class name.
i have changed few things
You should not use Selector by ID.
Because it’s an Unique query.
So You have to use ‘name’
See my jsfiddle.
https://jsfiddle.net/ChoHongRae/5g6ksbma/3/