I'm trying to make a code live preview form with jQuery, so when people type in the input, the related <span> will update.
JQuery:
var $comment = '';
$(function() {
$("input").keyup(function() {
var currClass = $(this).attr('class');
$comment = $(this).val();
$('span.'+currClass).html($comment);
return false;
});
});
HTML:
<label for="image-left-url">Image URL: </label>
<input id="image-left-url" class="image-left-url" value="http://"></input>
<code><pre><img src="<span class="image-left-url"></span>"/></pre></code>
My question is, for some inputs I have the value="xx" part. How can I make it so that if the input is blank, value="xx" doesn't show up (so that it doesn't show up in the <span>)?