Jquery $ ('# someID> div'). Each (function () {..}) does not work in IE

I do not encounter this problem when working on the local host, only when I access the page using the IP address of my system, it happens, and it only happens with IE! (works in all other browsers)

By the way, I am using Tomcat V6.0.0.29, IE8

I tried to debug the JS code using the IE developer tool debugger, of course, when I open with http://localhost:8080/ everything works fine, but when I use http://myIP:8080/ , this loop poses a problem: -

 $('#someId > div').each(function(){...}); 

As in this loop, it does not start at all, it just skips it. I checked the identifiers that they are fine and also works in localhost, why should this be a problem when accessing it using my IP?

Note: - a. (fix) The problem exists only in IE7, it works fine in IE8.

b. As it turns out, something strange is happening! I use IE8 when I open this web page using localhost, the developer tools show it works in IE8 standards, but when I use the IP address to access this page, the developer tools show that it works in IE7 standards. When I changed the standards to IE8, it worked (using the IP address)!

with. But the problem is why the hell doesn’t work with IE7! As with everything except the cycle mentioned above.

+4
source share
4 answers

Finally, I found out what caused the problem in IE7. Consider the following situation: -

 <div id="div1">abc <div id="div2">def <div>hjs</div> <div>zyx</div> </div> <div id="div3">xsj <div>ask</div> <div>iue</div> </div> </div> 

The jquery I wrote to go through these divs was something like

$ ("# divId> div"). each (function () {..});

Now for the first level, the div that intersects the divs directly inside the div with id "div1" worked fine in IE7, but when I did something like: -

$ ("# div2> div"). each (function () {..});

This worked in all browsers (even in IE8 !!), but not in IE7. This is because IE7 seems to require an accurate child selector. So for IE7 you need to write something like this: -

$ ("# div1> # div2> div"). each (function () {..});

to move a div inside a div with id "div2"

So the problem was due to my lack of knowledge about IE7! Sorry, thanks guys!

+2
source

IE is a culprit, it may turn out to be something evil, because the browser does not cache the page when loading from the local host, but reads it from the cache when using ip. Make sure you load the page to clear the cache from your ip.

+1
source

Check if your script is loaded using your IP address. Sometimes browsers do not load scripts in special situations (for example, if you want to download a script from an http source to an https page). Also you should check IE security configuration.
To check if your script is loaded or not, simply put the alert('loaded') statement at the beginning of your code.

0
source

This may be due to the group policy of your company to force Intranet sites using a specific version of IE in compatibility mode. I faced the same problem when presenting some IE10 + Javascript libraries on my page.

IE Compatibility View Settings

To get around this, you can either ask your IT company to change the policy, or make the browser not use the compatibility view with the following tag.

 <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> 

More details about this tag can be found in the section below.

fooobar.com/questions/20622 / ...

0
source

Source: https://habr.com/ru/post/1382437/


All Articles