JSFiddle

  • JavaScript Objects #4 is the latest revision

    JavaScript Objects

    console.log(2 + 2);
    console.log(2 + "2");
    console.log(2 + "2" + 2);
    console.log(2 + 2 + "2" + 2);
    console ...
  • display a random number between 1 and 70.

    display a random number between 1 and 70.

    function myFunction() {
        var x = Math.floor((Math.random() * 70) + 1);
        document.getElementById("demo").innerHTML = x;
    }
  • reverse a string in javascript

    reverse a string in javascript

    var str="sibeesh";
    str= str.split("").reverse().join("");
    console.log(str);
  • A number is undefined and isNaN is true, but the type is undefined. How?

    A number is undefined and isNaN is true, but the type is undefined. How?

    var a;
    console.log(a);
    console.log(typeof(a));
    console.log(isNaN(a));
    console.log(typeof(undefined));
    console.log(isNaN ...
  • Substring VS Slice

    Substring VS Slice

    var str="Sibeesh";
    var outSub= str.substring(3,7);
    console.log(outSub);
    var outSlc= str.slice(3,7);
    console.log ...
  • check a driopdown values exists in jquery

    check a driopdown values exists in jquery

    $(function(){
    var checkVal='1';
      $('#Liste option').each(function(){
          if (this.value == checkVal) {
          	console.log(checkVal+ ' is found!');
          }
      });
    });
    
  • regex - two part number, not ending with dot or comma

    regex - two part number, not ending with dot or comma

    
    var myReg = /^\d+(?:[.,]\d+)?$/;
    console.log(myReg.exec("123"));
    console.log(myReg.exec("123.123"));
    console.log(myReg.exec(".123 ...
  • infinite loop in jQuery

    infinite loop in jQuery

    var width = $(document).width() - $('#mydiv').width();
    $(document).ready(function() {
    
        function animateMydiv() {
            $('#mydiv').animate({
                    'left': width + 'px'
                }, 9000,
    
                function() {
                    $('#test').css ...
  • Change the ID of an element dynamically

    Change the ID of an element dynamically

        $(document).on('click', ".nuttonA",function(){
            alert("nuttonA is clicked "); 
            $("#buttonB").attr("id","notButtonB");
        });
    
        $(document).on('click', "#notButtonB",function(){
            alert("notButtonB ...
  • Count occurrences of array in string variable and return length

    Count occurrences of array in string variable and return length

    var search = ["ab", "cd", "ef"];
    var string = "ab yz cd wx ef uv ab yz cd";
    
    console.log(
      search.map ...