I don’t know why but hopefully, someone can help me out with the following code.
<script src="/jquery-1.7.2.min.js"></script>
<script>
$(".static_class").click(function(){
if($(this).val()==="expanded")
$(".widget_prev").append("<p>expanded</p>");
else $(".widget_prev").append("<p>minified</p>");
});
</script>
<div>
<input type="radio" name="ad_window" selected="selected" value="expanded" class="static_class" />Ad Window Expanded
<br />
<input type="radio" name="ad_window" value="minified" class="static_class" />Ad Window Minimized
<b>Widget Preview: </b>
<div class="widget_prev"></div>
</div>
Can’t seem to get the text appended. Wonder where the problem lies.
Make sure you wait for the elements to be in the DOM before you bind your click event. In the following, I’m using the short-form of
$(document).ready(), which is$(function(){ /* ... */ });Fiddle: http://jsfiddle.net/jonathansampson/drkCK/