views:

682

answers:

2

Hi everyone, I'm trying to implement a simple function using jqGrid, but it doesn't seem to work and I was wondering if anyone has an explanation.

Basically one column of jqGrid returns (through JSON)

<a href="#" id="special">Click</a>

Outside the column, I have a jQuery listener that is of the form

$("#special").click(function () { 
  alert("hi");
});

Now when I have the exact same a href outside the column, the alert pops up. It doesn't, however, when the code is inside the grid as part of JSON. Is that to be expected?

Thanks.

FYI the JSON response is along the lines of

\u003ca href=\"#\" id=\"special\"\u003eClick\u003c/a\u003e

but I doubt it's the issue because if I do

<a href="#" onclick="alert('Hi');">Click</a>

it works.

A: 

Basically I've given this up as a non-possibility. Bind each item using onclick, but don't expect it to work if you're trying to bind an element inside the grid using a function outside the grid.

Rio
Apparently this feature is implemented in the latest version of jqGrid.
Rio
+2  A: 

You didn't clarify in your question if you were binding the listener before or after the grid was populated - if you're setting it up beforehand, it would likely help to try using the .live method, as opposed to .click, to ensure it's picked up if loaded later.

For example:

$("#special").live("click",function () { 
  alert("hi");
});
Alex Osborn