Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Friday, 5 March 2021

Add and remove a class on click using jQuery

 


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>
jQuery(document).ready(function(){
jQuery('#btnSubmit').on('click', function() {
jQuery(this).addClass('toggle').removeClass('codepen');   
});
});
</script>

According To Question:

#jQuery add remove class onclick codepen
#Add Class jQuery
#jQuery Onclick Remove Class And Addclass
#toggle class jQuery
#Onclick Add And Remove Class To Body
#Add Class JavaScript
#jQuery Add Class On Click
#Remove Class In JavaScript
#Add Remove Class Onclick By jQuery


Saturday, 20 February 2021

Change Div Order In Mobile View By jQuery

 

Web View

                             
                           Before Change              After Change 



<html>
    <head>
<title>Change Div Order In Mobile View By jQuery.</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style type="text/css">
           body{
padding:20px;
   }
            #container {
                width:100%;
                margin: 0 auto;
text-align: center;
            }
.display_inline{
border: 2px solid;
width: auto;
display: inline-block;
padding: 150px 100px;
margin: 22px;
font-size: 50px;
color: #fff;
font-family: emoji;
}
#div1{
background:#1a3a5f;
}
#div2{
background:#79286c;
}
@media only screen and (max-width: 600px) {
.display_inline{
width: auto;
display: block !important;
bolder:2px solid red;
padding: 10%;
}
}
           
        </style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
    </head>
    <body>
       
        <div id="container">
            <div id="div1" class="display_inline">
<div class="center">
Div One
                </div>
                
            </div>
            <div id="div2" class="display_inline">
<div class="center">
                    Div Two
                </div>
            </div>  
        </div>
<script type="text/javascript">
function listenWidth( ) {
if (jQuery(window).width() <= 600) {
jQuery("#div2").remove().insertBefore(jQuery("#div1"));
} else {
jQuery("#div2").remove().insertAfter(jQuery("#div1"));
}
}
jQuery(document).ready(function(){
listenWidth();
});
jQuery(window).resize(function() {
listenWidth();
});
</script>
    </body>
</html>


According To Question:

#Change Div Position In Mobile
#How To Change Div Position In Responsive
#jQuery Change Order Of Divs
#Change Order Of Divs Responsive
#Div Order Change jQuery
#jQuery Change Column Order
#Javascript Reorder Divs
#Change Div Position By jQuery


Friday, 1 January 2021

How Can I Remove A Specific Item From An Array by jQuery?




//INPUT
var array = [2020, 2021, 2022, 2023];

console.log(array);

var index = array.indexOf(2020);
if (index > -1) {
  array.splice(index, 1);
}

// OUTPUT  : array = [2021, 2022, 2023]
console.log(array);

Note: Run This Code In Browser Console For Testing

According To Question:
#Remove Specific Element From Array Javascript
#Javascript Remove Object From Array By Value
#Remove Element From Array Jav
#Array Filter
#Splice Javascript
#Jquery Remove Item From Array By Index
#Lodash Remove Item From Array
#Remove Object From Json Array Javascript

Monday, 18 May 2020

The best way to detect a mobile device



<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
var isMobile = false;
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// some code write for mobile device...
isMobile = true;
}else{
isMobile = false;
}
</script>
</head>
<body>
<div>
<center><h1 id="device"></h1></center>
</div>
<script>
if(isMobile){
jQuery("#device").text("This is mobile device...");
}else{
jQuery("#device").text("This is not mobile device...");
}
</script>
</body>
</html>



Output:

This is...

Wednesday, 1 January 2020

How do I redirect to another webpage by jQuery?


There are many ways you can do page redirect to another webpage by jQuery.

Here I give you two example:
  1. Page redirect to another webpage on document ready by jQuery.
    <script>
    // Page redirect on document document
    jQuery(document).document( function() {
        // Similar behavior as an HTTP redirect
          window.location.replace("https://phpkishan.blogspot.com");  //OR
          window.location = "https://phpkishan.blogspot.com";  //OR
          window.location.href = "https://phpkishan.blogspot.com";  //OR
          window.location.assign("https://phpkishan.blogspot.com");
    }
    </script>

  2. Page redirect to another webpage on button clicking by jQuery.

    <button id="buttonID">Page redirect</button>

    <script>
    // Page redirect on button clicking
    jQuery(document).document( function() {
        jQuery( "#buttonID" ).click(function() {
            window.location.href = "https://phpkishan.blogspot.com/";
        });
    }
    </script>

Friday, 15 November 2019

How can I remove a particular value from an array in JavaScript with Example?


<!DOCTYPE html>
<html>  
<head>
    <title>How can I remove a particular value from an array in JavaScript with Example? -PHP Kishan</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" crossorigin="anonymous"></script>
    <script>  
    jQuery(document).ready(function(){
        orig_array = ['BattleGrounds', 'Fornite Battle Royale', 'League of Legends (LOL)', 'Counter-Strike: Global Offensive (CS: GO)', 'HearthStone', 'Minecraft', 'DOTA 2', 'Apex Legends', 'The Division 2', 'Splatoon 2', 'Rummy'];    //Ex: Game List
        document.getElementById("orig_array").innerHTML = orig_array;
      
      
        remove_game = orig_array.indexOf('Fornite Battle Royale'); // You can remove only one value (Game name)
        if (remove_game > -1) {
          orig_array.splice(remove_game, 1);
        }          
        document.getElementById("new_array").innerHTML = orig_array;
    });
    </script>
</head>
<body>
    <p><strong>Array Games List: </strong><br>=> <span id="orig_array"></span></p>  
    <p><strong>Reomve Game From List: </strong><br>=> Fornite Battle Royale</p>  
    <p><strong>New Array Games List: </strong><br>=> <span id="new_array"></span></p>  
</body>
</html>

Monday, 7 October 2019

How to redirect another webpage using JavaScript?



<!DOCTYPE html>
<html>   
<head>
    <title>How to redirect another webpage using JavaScript? -PHP Kishan</title>
    <script>   
        function new_Location(newurl) {       
            /* The wwindow.location method redirect to another webpage location. */
            window.location = newurl;
           
            // OR //
            /* The window.location.href() method redirect to another webpage location. */
            window.location.href = newurl;
           
            // OR //
            /* The window.location.assign() method loads a new location in the browser. */
            window.location.assign(newurl);
           
            // OR //
            /* The window.location.replace() method current location to redirect a new location in the browser. */
            window.location.replace(newurl);
        }

        var new_url = "https://phpkishan.blogspot.com/"; // Assigen New URL Location
    </script>
</head>
<body>
    <p>You can use any one method as per requirement for redirect your document location.</p>
    <input type="button" value="Redirect to new location" onclick="new_Location(new_url)">
</body>
</html>