Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9040503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:59:51+00:00 2026-06-16T09:59:51+00:00

I have a Javascript function that, when called, displays the CSS div #mapLoading and

  • 0

I have a Javascript function that, when called, displays the CSS div #mapLoading and appends the style display:block. The line of code which completes this action is as follows:

Code #1

 mapLoading.style.display = "block";

The function in its entirety is shown at the bottom of this question.


I also have the following jQuery code which appends the CSS class .weareloading when the element is hovered on with the mouse, then removes the class .weareloading once the CSS3 animations (rotate and fadeIn) complete.

Code #2

$("#mapLoading").hover(function(){
  $(this).addClass("weareloading");})
$("#mapLoading").bind("webkitAnimationEnd mozAnimationEnd animationEnd", function(){
  $(this).removeClass("weareloading")  
})

What I’d like to do – and the reason for this question – is the following:

  • Replace Code #1 with Code #2 in the Javascript function
  • Remove the mouse hovering requirement in Code #2 so that the function displayed below simply adds the class .weareloading then removes the class .weareloading once the animations are complete.

Unfortunately, the entire program is complex and holds many files, so I can’t provide a live example on jsFiddle. However, here is the above-referenced Javascript function that should hopefully provide enough context for this question:

Line 2 contains Code #1

function doSearch(keyword, type) {
 mapLoading.style.display = "block";
  currentCategory = type;
  var icon;

        if (markerGroups[type]) {

        for (var i = 0; i < markerGroups[type].length; i++) {
          markerGroups[type][i].setMap(null);
        }
        markerGroups[type].length = 0;
        }


  if (keyword.substr(0,3) == "db:"){ 
  var bounds = map.getBounds();
  var southWest = bounds.getSouthWest();
  var northEast = bounds.getNorthEast();
  var swLat = southWest.lat();
  var swLng = southWest.lng();
  var neLat = northEast.lat();
  var neLng = northEast.lng();
  var dbCat = keyword.substr(3);

  var filename = dbPath + "db.php?cat="+ dbCat + "&swLat="+ swLat + "&swLng="+ swLng + "&neLat="+ neLat + "&neLng="+ neLng + "&extendLat="+ extendLat + "&extendLng="+ extendLng;
    $.getJSON(filename, function(data) {
   var hider = document.getElementById(type).getAttribute("caption");
    if (hider != "hidden") {
        for (i = 0; i < data.results.length; i++) {
            var result = data.results[i];
                if (result.icon === "" ) {
                    icon = type;
                } else {
                    icon = result.icon;
                }
            cleanHTML = html_entity_decode(result.html);
            var xmlHTML = createXmlHTML(result.address, result.name, cleanHTML, result.url, result.geometry.location.lat, result.geometry.location.lng);
            var latlng = new google.maps.LatLng(parseFloat(result.geometry.location.lat), parseFloat(result.geometry.location.lng));
            createMarker(latlng, i, xmlHTML, type, icon, "db", result.name);
      }
  }
     mapLoading.style.display = "none";
});

  } else {
                var hider = document.getElementById(type).getAttribute("caption");
                if (type == "user") {
                var userName = document.getElementById(type).getAttribute("name");
                    if (userName === null) {
                            hider = "hidden";
                    } else {
                        keyword = "establishment";
                        searchName = userName;
                    }
                }
                if (hider != "hidden") {
                var searchName = document.getElementById(type).getAttribute("name");
                if (searchName === null){
                    searchName = "";
                } else {
                    searchName = "&name=" + searchName;
                }
                    var ctr = map.getCenter();
                    //alert("Center: " + ctr)
                    var jsonLAT = ctr.lat();
                    var jsonLNG = ctr.lng();
                    if (autoRadius === true){
                        searchRadius = distance( map.getBounds().getNorthEast().lat(), map.getBounds().getNorthEast().lng(), map.getBounds().getSouthWest().lat(), map.getBounds().getSouthWest().lng());
                    }
                    var JSON = dbPath + "jsonproxy.php?url=" + encodeURIComponent("https://maps.googleapis.com/maps/api/place/search/json?location=" + jsonLAT + "," + jsonLNG + "&radius=" + searchRadius + "&types=" + keyword + searchName + "&sensor=false");
                    $.getJSON(JSON, function(data) {
                            for (i = 0; i < data.results.length; i++) {
                              var result = data.results[i];
                              var latlng = new google.maps.LatLng(parseFloat(result.geometry.location.lat), parseFloat(result.geometry.location.lng));
                              var resultHTML = "api:" + result.reference;
                              createMarker(latlng, i, resultHTML, type, type, "api", result.name, result.icon);
                              if (hider == "hidden") {
                                markerGroups[type][i].hide();
                              }
                            }
                               mapLoading.style.display = "none";
                    });
                }
  }
  return 1;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:59:53+00:00Added an answer on June 16, 2026 at 9:59 am

    The first part is simple, change line 2 of the function to:

    $("#mapLoading").addClass("weareloading");
    

    I can’t see where in your function you’re doing the animation, so I’m not sure where to remove the class. If you’re using jQuery animation functions, they should have a callback that gets called when the animation is complete. In this callback function, put:

    $("#mapLoading").removeClass("weareloading");
    

    BTW, since you’re using jQuery, why do you have all that verbose raw JavaScript? E.g. why:

    document.getElementById(type).getAttribute("caption");
    

    when it could be:

    $('#'+type).attr("caption");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Javascript function that is called from the onchange method in a
I have a javascript function that toggles the display for rows in a table.
I have a Javascript function that returns the innerHTML of a div. I am
I have a JavaScript class that displays a partially-opaque div over top of the
I have this code that will load css/js/jst (javascript templates) using $.ajax and I'd
I have a java script function that i have called on body load mousemove()
I have this Javascript function that sends username and password to php file through
I have a JavaScript function that should only run on specific pages on a
I have a JavaScript function that looks like this: function recalculateWhatIfCurrentRate(aEle, aChangedLabel, recordID, yearEndCurrentRate)
I have a javascript function that calls a generic function to make an ajax

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.