JavascriptJquery

Jquery all time methods and functions

Jquery all time methods and functions

jquery
778Views

Hello, welcome to therichpost.com. In this post, I will tell you Jquery all time methods and functions. I personally like jquery very much. Most of my code is full with jquery. When I stuck in php or other language then that stuckness I remove with jquery code.

Today In this post, you will more code related to jquery.

1. jquery differents click functions:

$(“Div#id”).click(function(){
//you code
});

// for dynamic htmls

$(“Div#id”).on(‘click’, function(){
//you code
});

$(“Div#id”).on(‘click’, ‘.divclass’, function(){
//you code
});

2. Open Bootstrap Modal Popup with jquery:

$(‘#ModalId’).modal(‘show’);

3. Add css to div with jquery:

$(‘#DivId’).css(‘width’, ‘100px’);

4. Remove commas in array data with jquery:

arr.join(“\n”)

There are so many jquery code, tricks and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

48 Comments

  • // jquery custom validations on button click

    $(“.formbtn”).on(“click”, function(){

    var i=0;
    var j=0;
    if($(“#firstname”).val()==””)
    {
    i = 1;
    $(“#firstname”).css(“border”, “1px solid red”);
    }
    else
    {
    i = 0;
    $(“#firstname”).css(“border”, “1px solid rgba(0, 0, 0, 0.15)”);
    }

    if($(“#lastname”).val()==””)
    {
    j=0;
    $(“#lastname”).css(“border”, “1px solid red”);
    }
    else
    {
    j = 0;
    $(“#lastname”).css(“border”, “1px solid rgba(0, 0, 0, 0.15)”);
    }

    if(i==0 && j==0)
    {
    alert(“All Done :)”);
    }
    else
    {
    alert(“All Not Done :(“);
    }

    });

  • // get select box text value on change event

    $(“.addnewservice .select-service”).on(“change”, function(){
    var optionSelected = $(this).find(“option:selected”);
    var valueSelected = optionSelected.val();
    var textSelected = optionSelected.text();

    });

  • Here more:
    ========

    set default flag in intl-tel-input
    open -> intlTelInput.min.js -> find-> preferredCountries-> add county code:
    That is it

  • Please help:

    How to write a JavaScript code using if condition….user status should active its show green color button on…..it user status is disable it shows red color button

  • Here you can check the answer:

    if($(“#divwhereuserstatus”).text()==”active “)
    {
    $(“#button”).css(“background-color”, “green”);
    }
    else
    {
    $(“#button”).css(“background-color”, “red”);
    }

    Hope this solve your problem..

    • for ajax use this:

      $.ajax({
      type: ‘POST’,
      url: “url.php?action=saveData”,
      data: data,
      success: function(resultData) { if($(“#divwhereuserstatus”).text()==”active “)
      {
      $(“#button”).css(“background-color”, “green”);
      }
      else
      {
      $(“#button”).css(“background-color”, “red”);
      } }
      });

    • success: function( result){
      console.log(result);
      if(userstatus == 1){
      $(“#active”).show();
      }
      else{

      $(“#inactive”).show();
      like this but i m not getting

  • success: function( result){
    console.log(result);
    if(userstatus == 1){
    $(“#active”).show();
    }
    else{

    $(“#inactive”).show();
    like this but i m not getting

  • var error = “”;
    $(document).ready(function(){
    $(“#submit”).on(“click”, function(){
    $(“.error”).html(“”);
    var number = $(“#zip”).val(),
    userstatus = 1;

    flag = true;

    if(number === “” || !regex(number)){
    error= “Enter correct 6 digit number Eg:123456”;
    flag = false;
    }

    if(!flag){
    $(“.error”).html(error).css({“color”:”#FF0000″ , “font-weight”:”bold” , “text-align”: “center” , “margin”: “px 0px”});
    }
    else{
    $.ajax({

    data : {“layout” : 1000, “fname” :name ,”lname”:lname, “email”: email, “password” : password , “gender” : gender},
    method : “POST”,
    success: function( result){
    console.log(result);
    if(userstatus == 1){
    $(“#active”).show();
    }
    else{

    $(“#inactive”).show();

    }
    },

    })
    }

    })

    })

    html

    Enter Your Details
    Active
    Inactive

  • var error = “”;
    $(document).ready(function(){
    $(“#submit”).on(“click”, function(){
    $(“.error”).html(“”);
    var number = $(“#zip”).val(),
    userstatus = 1;

    flag = true;

    if(number === “” || !regex(number)){
    error= “Enter correct 6 digit number Eg:123456”;
    flag = false;
    }

    if(!flag){
    $(“.error”).html(error).css({“color”:”#FF0000″ , “font-weight”:”bold” , “text-align”: “center” , “margin”: “px 0px”});
    }
    else{
    $.ajax({

    data : {“layout” : 1000, “fname” :name ,”lname”:lname, “email”: email, “password” : password , “gender” : gender},
    method : “POST”,
    success: function( result){
    console.log(result);
    if(userstatus == 1){
    $(“#active”).show();
    }
    else{

    $(“#inactive”).show();

    }
    },

    })
    }

    })

    })

    • The localstorage.getitem() method of the Storage system, when passed a key name, will return that key’s value.:
      ======================
      var currentColor = localStorage.getItem(‘bgcolor’);
      document.getElementById(‘bgcolor’).value = currentColor;

      //also you can store temprary value like below method
      // Save data to the current local store

      localStorage.setItem(“username”, “John”);

      // Access some stored data
      alert( “username = ” + localStorage.getItem(“username”));

  • its like when we login as a user his details shud b appeared on top right corner ..like example in gmail we login n compose mail everythin n wen to signout wil go to our profile pic n signout ryt…..it should show our profile until we are in that page ..otherwise logout

  • //also you can store temprary value like below method
    // Save data to the current local store

    localStorage.setItem(“username”, “John”);

    // Access some stored data
    alert( “username = ” + localStorage.getItem(“username”));

    how to access using json

  • with this we create custom json data in js:

    <script type=”text/javascript”>
    var data = {‘name’: ‘therichpost’, ‘age’: 1};
    </script>

  • this thing hav to put in js folder..
    actually i tried with
    if(session === “”){
    localStorage.getItem(“session”);
    {“session” :
    { “name”: “abc”}
    }
    window.location=”login.php”;
    }

    • try this:

      var session = { ‘session’: ‘abc’};
      localStorage.setItem(‘session’, JSON.stringify(session));
      session = JSON.parse(localStorage.getItem(‘session’));
      if(session[‘session’]!=””)
      {
      window.location=”login.php”;
      }

  • try this:

    var session = { ‘session’: ‘abc’};
    localStorage.setItem(‘session’, JSON.stringify(session));
    session = JSON.parse(localStorage.getItem(‘session’));
    if(session[‘session’]!=””)
    {
    window.location=”login.php”;
    }

Leave a Reply

Positive SSL