Bug Tracker

Modify

Ticket #2998 (closed bug: invalid)

Opened 5 years ago

Last modified 14 months ago

attr('onclick',value)

Reported by: shadow Owned by:
Priority: major Milestone: 1.3
Component: event Version: 1.2.6
Keywords: Cc:
Blocking: Blocked by:

Description

The problem is: we have something like this in html code:

<div class="pages" onclick="loadPage(1)"></div>
<div class="pages" onclick="loadPage(2)"></div>
.
.
.
<div class="pages" onclick="loadPage(n)"></div>

<div id="page"></div>

jQuery code:

function loadPage(page) {
	$.post("url", {
		page:	page
		},
		function (data) {
			v = parseInt($('div[class="pages"]:first').text());
			// putting data returned from .post to div with id 'page'
			$('#page').html(data);

			t = parseInt($('div[class="pages"]:first').text());

			// Rewriting onclick
			$('div[class="pages"]').attr('onclick', "loadPage('" + v + "')");
			$('div[class="pages"]:contains(' + page + ')').attr('onclick', '');
		}
	);
}

In jQuery 1.2.4 this code works, in versions 1.2.5,1.2.6 don't.
After 1 execution of loadPage() (rewriting onclick with attr() within function loadPage) browers don't catch click event anymore.

Change History

comment:1 Changed 5 years ago by flesler

  • Status changed from new to closed
  • Resolution set to invalid
  • Component changed from core to event

This doesn't work on IE. Inline/obstrusive string event handlers are not really supported. We decided that there's no point in handling something like this, because isn't crossbrowser and it's deprecated coding.

You should use bind or at least, functions as handlers. Don't use function with .attr(). Use .each and set them on each element.

$().each(function(){
   this.onclick = function(){
     // ....
   };
});

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.