Bug Tracker

Modify

Ticket #7480 (closed bug: invalid)

Opened 3 years ago

Last modified 2 years ago

Has attribute selector not working for <a> elements

Reported by: ryan@… Owned by:
Priority: undecided Milestone: 1.5
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocking: Blocked by:

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

comment:1 Changed 3 years ago by jitter

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 3 textContent 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.

comment:2 Changed 3 years ago by jitter

  • Keywords needsreview added

comment:3 Changed 2 years ago by dmethvin

  • Keywords needsreview removed
  • Status changed from new to closed
  • Resolution set to invalid

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.