Sunday, June 24, 2012

Live Preview with jQuery

Live Preview with jQuery

javascript
Contains javascipt code. $(".word").keyup(function(){} - word is the class name of anchor input field. Using $(this).val() calling input field value. 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js
"></script>
<script type="text/javascript">
$(function() 
{
$(".word").keyup(function() 
{
var word=$(this).val();
$(".word_preview").html(word);
return false;
});
});
</script>

HTML code

<input type="text" name="word" class="word" />
http://9lessons.info/<span class="word_preview"></span>

CSS
body
{
font-family:Arial, Helvetica, sans-serif;
background:#FFFFFF;
}
.word_preview
{
color:#cc0000
}
.word
{
width:150px; height:26px; font-size:18px;
}

1 comment:

  1. What event should I trigger if I have to merge two html elements like radio button and text box. Finally I would like to assemble values from forms with various html elements and generate html code.

    ReplyDelete