Showing posts with label jquery. Show all posts
Showing posts with label jquery. Show all posts

Thursday, 3 January 2013

Check element exists in javascript

,
Code to check if element exist of not.
 You can check element exist or not with javascript by it id or name.

Check Element exist in Javascript

With Id :

var check = document.getElementById("elementId");
if(check.length != 0)
{
      alert('I am present');
}

With Name:
 
var check = document.getElementsByName("elementName");
if(check.length != 0)
{
      alert('I am present');
}


Check Element exist in jQuery

With Id :

if ($('#elementId').length > 0) { 
    // it exists 
}
Read more →

Monday, 10 December 2012

Sliding div left side

,
Sliding div left side with jquery animate method.Following are the step to do that

JAVASCRIPT CODE
$(document).ready(function() {
     $('button').click(function() {
       $("#slidingDiv").animate({width: 'toggle'});
     });
});
CSS CODE 
#slidingDiv{
     width: 200px;
     height: 50px;
     background-color: red;
} 
HTML CODE
<body>
   <button>CLICK ME</button>
   <br />
   <div id="slidingDiv"></div>
</body>
Read more →

Tuesday, 3 July 2012

Using multiple version of jQuery on same page

,
During working on project you might have encounter this problem of jquery.
There is problem coming when you are using jquery1.6 in project and you have to use jquery plugin which require jquery1.4 and it is incompatible with 1.6. So what you do remove that plugin or change your jquery  version.There is also another solution which is define below.You can use jQuery of different version easily with this following step.

<script type="text/javascript" src="jquery1.4.2.js">
</script>  
<script type="text/javascript">  
   var jq_4 = jQuery.noConflict();  
</script>  
<script type="text/javascript" src="jquery1.6.js">
</script>  
<script type="text/javascript">  
   var jq_6 = jQuery.noConflict();  
</script>  
<script type="text/javascript" src="jquery1.7.js">
</script>  
<script type="text/javascript">  
   var jq_7 = jQuery.noConflict();  
</script>  
<script type="text/javascript">  
   // You can use different instance of jquery library.   
   jq_4(document).ready(function () {  
     // so now you can use jquery jq variable instead of $ .   
     jq_4("div").hide();  
   });  
   jq_7(document).ready(function () {  
     // so now you can use jquery jq variable instead of $ .   
     jq_7("div").hide();  
   });  
</script>  
Read more →

Monday, 7 November 2011

Using jQuery with other javascript library

,
You can use jQuery with other javascript framework easily with this following step.

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
 <script type="text/javascript">  
     var jq = jQuery.noConflict();  
     jq(document).ready(function () {  
       // so now you can use jquery jq variable instead of $ .  
        jq("div").hide();  
     });  
  // Code that uses other library's $ can follow here.  
 </script>
Read more →