Opened 12 years ago
Closed 12 years ago
#7480 closed bug (invalid)
Has attribute selector not working for <a> elements
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | 1.5 |
Component: | unfiled | Version: | 1.4.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
It works fine for other elements like <p>.
A test case:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="application/x-javascript" src="./jquery.js"></script> <script type="application/x-javascript"> <![CDATA[ function go() { $("[text]").each( function() { $(this).text($(this).attr("text")); } ); } ]]> </script> <title></title> </head> <body onload="go();"> <a text="foo"></a> <p text="bar"></p> </body> </html>
Fails under Firefox 4.0b8pre and Epiphany 2.30.2.
Change History (3)
comment:1 Changed 12 years ago by
comment:2 Changed 12 years ago by
Keywords: | needsreview added |
---|
comment:3 Changed 12 years ago by
Keywords: | needsreview removed |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Like jitter said, HTML5 has claimed the text
attribute and several browsers already implement it. (IE6/7/8 does not though.) Whenever you're adding custom attributes, it's a good idea to prefix with something like x-
or use the data-
attribute support sanctified by HTML5.
Note: See
TracTickets for help on using
tickets.
Not sure if this is a jQuery bug.
AFAIK with HTML 5 a
text
attribute was introduced for link tags (see spec) which contains the same as the DOM 3textContent
property.If you try this test case in different browsers you might get very different results.
In many modern browsers you will get two alerts saying "link text" and "bar" instead of "foo" and "bar". In older browser you might get "foo" and "bar" when they have no HTML 5 support yet.