Error in jquery and IE6-7 attribute selector

I am trying to implement a jQuery script to handle some areas inside an image map. I use $ ('area [shape = "poly"]') as a selector to get the areas of interest to me. It works fine in IE8 and Firefox, but does not select items in IE6 or IE7.
This is a test page that shows this problem. I don't know if this is a jQuery bug or am I doing something wrong.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
 var areas = $('area[shape="poly"]');
 alert('areas: ' + areas.length);
});
//]]>
</script>
 <title>Test</title>
</head>
<body>
<img id="img1" src="nothing.gif" style="width:300px; height:300px; border: 2px solid black" usemap="#map1"/>
<map id="map1">
<area shape="rect" title="rectArea" coords="126,112,231,217" alt=""/>
<area shape="poly" title="polyArea1" coords="274,72,262,70,251,68,240,67,228,66,217,67,206,68,194,70,183,72,181,63,192,60,204,58,216,57,228,56,240,57,252,58,264,60,276,63" alt=""/>
<area shape="poly" title="polyArea2" coords="241,194,235,193,228,193,222,193,216,194,196,119,204,117,212,116,220,115,228,115,237,115,245,116,253,117,261,119" alt=""/>
</map>
</body>
</html>

It shows 2 in IE8 and Firefox and 0 in IE6-7
Thanks, Guillermo

+3
source share
3 answers

It works if you delay the value:

var areas = $('area[shape="POLY"]');
+7
source

IE6. :

[title*="poly"]

(*= )

+2

Try the following: $ ("Area [shape = poly]")

I have this code correctly selected in IE6

    <script>
      $(document).ready(function() {
        $("#button").click(function(){
          $("div[shape=poly]").remove();
        });
      });          
    </script>

<button id="button">Button</button>
<div shape="poly">p</div>
<div shape="poly">p</div>
<div shape="s">s</div>
<div shape="poly">p</div>
<div shape="poly">p</div>
0
source

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


All Articles