I have the following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#widget_list").hide();
$("#click_me").click(function() {
$(this).parents( "#clipboard" ).find( "#widget_list" ).toggle();
});
});
</script>
</head>
<body>
<div id="clipboard">
<div href="#" id="click_me" style="border:solid 1px black;text-align:center;cursor:pointer;">
\/
</div>
<div id="widget_list" style="border:solid 1px black;text-align:center;">
some stuff here
</div>
</div>
some other stuff here
</body>
</html>
Instead of hard coding the text some stuff here into #widget_list. How do I add that text to #widget_list, when it’s toggle state is visible and how do I remove that text from #widget_list when it’s toggle state is hidden?
demo http://jsfiddle.net/QFTsb/1/ or http://jsfiddle.net/QFTsb/3/
Using
.is(":visible"): http://api.jquery.com/visible-selector/You can see you will get alert in the demo when it will be visible or now in toggle
This will help
code