Check and uncheck checkbox in Jquery

<input type="checkbox" id="nat_cover_letter">
<select id="check_uncheck">
<option value="0">Select</option>
<option value="1">Check</option>
<option value="2">Uncheck</option>
</select>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$('#check_uncheck').change(function(){
if(this.value==1)
{
$('#nat_cover_letter').attr('checked',true); // Check checkbox
}
else if(this.value==2)
{
$('#nat_cover_letter').attr('checked',false); // uncheck checkbox
}
else
{
alert('none');
}
});
</script> ...  Read More

Share This:


checkbox is checked or not in jquery

<input value="600.00" type="checkbox" name="cover_letter" id="nat_cover_letter">

<script>

$('#nat_cover_letter').change(function() {
if($(this).is(":checked")) {
alert('checked');
}
else
{
alert('unchecked');
}
});

</script>

Or you can check at run time as well like this :

<script>

if($("#nat_cover_letter").prop('checked') == true)
{
alert('checked');
}
else
{
alert('unchecked');
}

</script>

Share This:


Get and Set HTML attributes in jquery

<input type="button" id="get_attribute" value="Get Attribute">
<input type="button" id="set_attribute" value="Set Attribute">
<input type="button" id="set_multiple_attribute" value="Set Multiple Attribute">
<a href="/" target="_blank">Coding 4 Developers </a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$('#get_attribute').click(function(){
var link = $('a').attr('href');
alert(link);
}); ...  Read More

Share This:


Get and Set HTML Content - text(), html(), and val() in jquery

<input type="button" id="get_text" value="Get Text">
<input type="button" id="set_text" value="Set Text">

<input type="button" id="get_html" value="Get Html Content">
<input type="button" id="set_html" value="Set Html Content">

<input type="button" id="get_val" value="Get Textbox Value">
<input type="button" id="set_val" value="Set Textbox Value">
<p>Paragraph <b>text</b></p>
<input type="text" value="Hello jquery world" id="txt_box">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$('#get_text').click(function(){
var txt = $('p').text();
alert(txt);
}); ...  Read More

Share This:


show,hide and toggle in jquery

In Jquery, Hiding and showing the content is much easier than JavaScript. You can show or hide the content in some magical ways which I have used below like tootgle or delay.

Here is an example to show or hide data in Jquery.

 

Share This:


Object oriented programming in jquery/javascript

With the basics out of the way, we'll now focus on object-oriented JavaScript (OOJS) . This article presents a basic view of object-oriented programming with an example.

 

Share This:


Events in Jquery

All user actions that a web page can respond to are called events.
An event represents the precise moment when something happens.

Examples:

  • moving a mouse over an element
  • selecting a radio button
  • clicking on an element

Here I'm giving an example of events in Jquery.

 

Share This:


Check background or foreground status of web app

I'd like to check weather my web application is running in background or foreground, You can check it very easily in JavaScript. hasFocus() is the function which tells that your window is active or not.

Here in below example I have create checkForeGroundBackGround() function and inside the body of it we check the window status.

We call back checkForeGroundBackGround() function periodically to check the status.

window.document.hasFocus() returns the web app status true if app is in foreground and false if app is in background. ...  Read More

Share This:


Check internet connection on webpage

We can check the internet connection so that if there is no internet in between we can let user know that no internet connection.
Here in below example we call the checkInternetConnection() function periodically. So that we can detect the internet connection on web page.

Here we are checking internet connection by navigator.onLine. It returns true if there is internet connection and returns false if there is no internet connection. 

Share This: