jQuery add text to span when div is visible -
<div class="box"> <span class="test"></span> </div> <div class="row"></div> <input type="button" value="add" id="button"> <style type="text/css"> .box { display: none; } </style>
above div not visible when page load. making div visible after button click. want append text span when div visible.
$('#button').on("click",function(e){ e.preventdefault(); $('.box').clone().show().append('.row'); });
i tried
1) $(".box").closest(".test").text("hello"); 2) $(".box").find(".test").text("hello");
but not adding text span.
try :
$(document).ready(function(){ $("button").on("click",function(){ $(".box").find(".test").text("hello"); $(".box").show(500); }) })
final code :
<!doctype html> <html lang="en"> <head> <style type="text/css"> .box { display: none; } </style> </head> <body> <div class="box"> <span class="test"></span> </div> <div class="row"></div> <button>show div</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").on("click",function(){ $(".box").find(".test").text("hello"); $(".box").show(500); }) }) </script> </body> </html>
Comments
Post a Comment