Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I have followin script in my page to highlight the map dynamically.It's gives result but after loading the page, all my browser get sucked, or infinitely hanged.

JavaScript
<script>
       function highlight(list) {

           var jsVariable = list;
           var area = document.getElementsByTagName('area')
           var ary = []
           for (var zxc0 = 0; zxc0 < area.length; zxc0++) {
               ary.push(area);
           }
           var isfound = false;
           for (var i = 0; i < area.length; i++) {
               isfound = false;
               for (var j = 0; j < jsVariable.length; j++) {
                   var SpliData = jsVariable[i].trim().split(":");
                   if (area[i].getAttribute('title').trim() == SpliData[0].trim()) {
                       isfound = true;
                       $(area[i]).each(function ()//get all areas
                       {
                           $(this).addClass('Highlight_' + i)
                           var data = {};
                           $('.map').maphilight();
                           data.alwaysOn = true;
                           data.fillColor = SpliData[1];
                           $(this).data('maphilight', data).trigger('alwaysOn.maphilight');
                       });
                   }
                   if (!isfound) {
                       $(area[i]).each(function ()//get all areas
                       {
                           $(this).addClass("NoHighLight");
                       });
                   }
               }
           }
       }
   </script>

</pre>
What should be the reason for that?

FYU, The browser starts to hang after adding the following part
JavaScript
$('.map').maphilight();
data.alwaysOn = true;
data.fillColor = SpliData[1];
$(this).data('maphilight', data).trigger('alwaysOn.maphilight');


Since this part is used to highlight the map dynamically.

Please help me out.
Posted
Updated 20-Jul-14 23:49pm
v2

this resulting in never ending recursion.
use e.stopPropagation();
This would prevent triggered event to propagate
 
Share this answer
 
v2
Comments
VigneshKumar957 21-Jul-14 6:20am    
Can you please explain with example.I'm new to this
mcdubey 21-Jul-14 6:51am    
what are you trying to do on that line?
please go through this link

http://stackoverflow.com/questions/8745253/jquery-maphilight-using-onclick-method
Change your script as follows:

Since your SplitData using **I** variable instead of **j** variable. Also use RemoveClass method before Adding Classes. This may made your function recursively.

C#
<script>
        function highlight(list) {
            var jsVariable = list;
            var area = document.getElementsByTagName('area')
            var ary = []
            for (var zxc0 = 0; zxc0 < area.length; zxc0++) {
                ary.push(area);
            }

            var isfound = false;

            for (var i = 0; i < area.length; i++) {
                isfound = false;
                for (var j = 0; j < jsVariable.length; j++) {

                    if (area[i].getAttribute('title').trim() == jsVariable[j].trim().split(":")[0].trim()) {

                        isfound = true;

                        $(area[i]).each(function ()//get all areas
                        {
                            $(this).removeClass().addClass('Highlight_' + i)
                            var data = {};
                            $('.map').maphilight();
                            data.alwaysOn = true;
                            data.fillColor = jsVariable[j].trim().split(":")[1].trim();
                            $(this).data('maphilight', data).trigger('alwaysOn.maphilight');
                        });
                    }
                    if (!isfound) {
                        $(area[i]).each(function ()//get all areas
                        {
                            $(this).removeClass().addClass("NoHighLight");
                        });
                    }
                }
            }
        }
   </script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900