Skip to main content

Bug Tracker

Side navigation

#2998 closed bug (invalid)

Opened June 06, 2008 11:02AM UTC

Closed June 10, 2008 08:11PM UTC

Last modified March 15, 2012 04:14PM UTC

attr('onclick',value)

Reported by: shadow Owned by:
Priority: major Milestone: 1.3
Component: event Version: 1.2.6
Keywords: Cc:
Blocked by: Blocking:
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.

Attachments (0)
Change History (1)

Changed June 10, 2008 08:11PM UTC by flesler comment:1

component: coreevent
resolution: → invalid
status: newclosed

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(){
     // ....
   };
});