You are not counting the length of array returned when you split the text of the divs. Change your code to this.
$('.intro_text').each(function() {
var lines = $(this).find("div").text().split("n").length;
var maxLine = 5;
if(lines >= maxLine){
$(this).after("<button>toggle</button>");
}
});
Problem :
I’m trying to count the number of lines in a string for each div. But I would also like to set a maximum number and if the string inside a div is equal/greater to that number to show a button.