Day: January 17, 2018

How to check div is hide or show using jQuery?

If you want to check that div is block(visible) or none then you can do this very easily . Suppose your div id = “test” -> for testing purpose if you use class = “test” then need to update code For checking Block or visible then use this for your select test is ID . This is simple code

1. if ($('#test').is(':visible')) {}

2. if ($('#test').css('display') == 'block'){}

3. if ($('#test').not(':hidden')){}

if you want to check this using class name

1. if ($('.test').is(':visible')) {}
2. if ($(your_element).is(':visible')) {}

This is other option for checking none or hide then use this code if your selector is id

1. if ($('#test').not(':visible')){}

2. if (!$('#test').is(':visible')){}

3. if ($('#test').css('display') == 'none'){}

4. if ($('#test').is(':hidden')){}

if you use class name then code is

1. if ($('.test').not(':visible')){}
2. if ($(your_element).not(':visible')){}

hop e it will help you. if you have face any problem then inform me.


Input tab index auto jump using jQuery.

In html form or other some time need tab auto jump when max length is covered. We can do it easily javascript code.

First create simple html code

<input size="2" tabindex="1" id="one"
maxlength="2" onkeyup="toUnicode(this)" />

<input size="2" tabindex="2" id="two"
maxlength="2" onkeyup="toUnicode(this)" />

<input size="2" tabindex="3" id="three"
maxlength="2" onkeyup="toUnicode(this)" />

then create javascript code. this is javascript code.

function toUnicode(elmnt)
  var next;
  if (elmnt.value.length==elmnt.maxLength)
    next=elmnt.tabIndex + 1;
    //look for the fields with the next tabIndex
    var f = elmnt.form;
    for (var i = 0; i < f.elements.length; i++)
      if (next<=f.elements[i].tabIndex)

then browse it and press onkeyup then automatic go to next input field.


Get all href value using jquery and replace it.

If you want to get all link using jQuery then you can use this code easily. Here is code which get all link using each function then check , if value is something and you want to change it.

<script type="text/javascript">
$('a').each(function() {
var value = $(this).attr('href');
$(this).attr('href', '');

if you face any problem then please inform me.