Showing posts with label Jquery. Show all posts
Showing posts with label Jquery. Show all posts

8/04/2011

How to uncheck Radio button by jquery








Write the Below code to Unchecked Radio Button by Jquery




<script type="text/javascript">
$(document).ready(function(){
$("#btn").click(function(){
$('input[name="rd"][type="radio"]:checked').each(function(){
$(this).attr("checked", false);
});
});
});
</script>






<form action="" name="aa" method="post">
<input type="radio" name="rd" value="1"/>
<input type="radio" name="rd" value="2"/>
<input type="radio" name="rd" value="3"/>
<input type="button" id="btn" value="Click" />
</form>

4/19/2011

How to Add option to select box by jquery


I have write the below code to add option to select drop down by jquery. Add value to the below input box then click on add button.You can see the effect.That option will be added to the below selectbox





The code you need to write is



$('#selectbox').append($("<option></option>").attr("value",option_value).text(text_to_display));

11/26/2010

How to change value of input text by jquery

I was searching in the internet for this solution ,But I couldn't find the proper solution.But I tried it myself so I think to share with all.


First i have created one input text with id inputText by this html code .

<input type="text" id="inputText" value="1" />




Now I wrote the following code in jquery to change value 1 to 5



$(document).ready(function(){

$('#inputText').val('5');

}

9/05/2010

difference between append() and html() in jquery

.aapend() and .html() is the most usefull method in jQuery.But these are far different from one another, .append() add some value with the existing one.whether .html() do the same but it removes the old value
Here is an example is given



<ul id="test">

<li>test</li>


</ul>




Now I will use .append() to add one
<li>, For that I will write

<script type="text/javascript>"

jQuery("#test").append("<li>test1</li>");

</script>




The output of this jQuery will be

<ul id="test">

<li>test</li>

<li>test1</li>

</ul>



Now if I
use .html() to add one <li>, For that I will write

<script type="text/javascript>"

jQuery("#test").html("<li>test1</li>");

</script>



The output of this Script will be

<ul id="test">

<li>test1</li>

</ul>



Here in this example .append() add one extra <li>, whether .html() removes the old one with new one. This is the main difference between .append() and .html() in Jquery

4/06/2010

Add a css Class Using Jquery




To use Css Class in an HTML Tag we can use a Jquery function addClass(). This function add a css class into your HTML tag.The most intresting things is that you can use this class on a eventhandler also, To get effects when a client/user response on it.

This is an example to add a css class into a Html Tag


<script type="text/javascript">

$(document).ready(function(){

$('.click').click(function(){

$('p').addClass('green');

});

});

</script>

<style type="text/css">

.green{ color:green;}

</style>


Write this code into your body tag

<button class="click">Click Me</button>


What is Jquery and How it Works




Jquery is a Library fucntion of Javascript.It's very easy to write and very much faster than Javascript. When we use onLoad event handler on body tag ,the onload function will fired when all body content will download successfully ,that means all the image should download completely,then only this event will fired.But in Jquery when your Html DOM(Document Object Model) will load completely than the Jquery function can be fired,it's no need to wait for downloading any Image.That is why it is very nuch popular than other language/script.



For example I am going to give red color into all h1 tag When this page will loaded. For that i will write

<script type="text/javascript">

$(document).ready(function(){

$('h1').css('color','red');

});

</script>



Before Run this script You need to link JQUERY Library into your page which you can get from these links

http://code.jquery.com/jquery-1.4.2.min.js

or you can use this one

http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js


Attach any one of this script then You can see the effect only