javascript - jQuery Toggle div class on load depending on the content height -
i have dynamic content loaded on template. default div background-color yellow, when teh content longer 300px div toggles or appends class wil change background-color red. below code.
<!doctype html> <head> <title>untitled document</title> <style type="text/css" media="all"> .short {background-color:yellow;padding:30px; width:200px;} .long {background-color:red;padding:30px;width:200px;} </style> </head> <body> <div class="short">div content</div> </body> </html>
try this
$(document).ready(function(){ $(".short").each(function(){ if($(this).height() > 300){ $(this).removeclass("short").addclass("long"); } }); });
Comments
Post a Comment