Usefull jQuery and Javascript Examples
In our daily life we need to use some jQuery methods like addClass, removeClass, add ID or remove ID etc. So today i created a single page where user can find this all in one place.
1) jQuery addClass()
1) jQuery addClass()
    $( "#YOURID" ).addClass( "yourClass" );
2) jQuery removeClass()
    $( "#YOURID" ).removeClass( "yourClass" );
3) jQuery Add ID to Div()
    $( "#YOURID" ).attr('id', 'value');
4) jQuery Remove ID from Div()
    $( "#YOURID" ).removeAttr('id');
5) String replace
    var str = "My name is Hardik";
var res = str.replace("Hardik", "HK");
var res = str.replace("Hardik", "HK");
6) Get value of text box
    var myval = $("#txtname").val();
    alert(myval );
7) Set value of text box
    $("#txtname").val("something");
8) Check element has class
    if($("#YOURID").hasClass("ClassName"))
{
alert("Class found");
}
{
alert("Class found");
}
    else
{
alert("Class not found");
}
{
alert("Class not found");
}
9) Submit page
    $("#FORMID").submit();
10) Jquery ajax function
$.ajax({
type: "POST",
url: "(URL OF YOUR PAGE)",
data: 'id='+id+'&name='+name,
success: function(data)
{
}
},
error: function(xhr, ajaxOptions, thrownError) { alert(xhr.responseText); }
});
10) Jquery ajax function
$.ajax({
type: "POST",
url: "(URL OF YOUR PAGE)",
data: 'id='+id+'&name='+name,
success: function(data)
{
}
},
error: function(xhr, ajaxOptions, thrownError) { alert(xhr.responseText); }
});
Please support us, Like us on Facebook.
Subscribe to:
Post Comments (Atom)

        
0 comments:
Post a Comment