On Sep 15, 6:09 pm, sirrocco wrote:
> Let's say you have a :
>
> asd
>
> I want to get the onclick text in a variable - something like
>
> var onclick = $('a').attr('onclick');
>
> The problem is that the onclick variable now is a function and if I
> try to execute , this wil be the document
I think you need to set the context for the function to that of the
link using the JavaScript call function... like:
function DoSomething( ctx ){
alert( ctx.text );
}
var linky = $('a');
var onclick = $('a').attr('onclick');
onclick.call(linky[0]); // Alerts 'asd'
BTW: the linky[0] get
Damn ... I somehow thought this would be easy to achive .
The whole idea was to not change existing code
Still .. if anyone has any more ideas :). Somehow it seems that this should
be doable.
On Tue, Sep 15, 2009 at 6:03 PM, MiKiTiE wrote:
>
> Ok, I've done some tests and here is my sugge
Ok, I've done some tests and here is my suggestion.
First of all, should just ask - I assume you are calling it after the
element? Probably is obvious, but thought I'd check.
Ok, here's the deal: "onclick" is not really an attribute but a mouse
event. Therefore jQuery will take the contents as a
>Perhaps then you can extract it as text like I mentioned in my first
post, then store it in a variable?
How do I extract it like text ? Calling the .text() method, as
expected doesn't return what I need - DoSomething(this);
On Sep 15, 3:30 pm, MiKiTiE wrote:
> Perhaps then you can extract it a
Perhaps then you can extract it as text like I mentioned in my first
post, then store it in a variable?
As I am not sure what your function does or why it needs to be applied
this way, I can't solve the problem exactly - but why not just use an
event instead of an onclick in the element? That is
Well .. that's the problem - i tried it like that and it didn't work.
When setting the attribute back on the link, the this in DoSomething
(this); is not the link, but the window.
On Sep 15, 11:41 am, MiKiTiE wrote:
> Sorry I should have written
>
> $('a').attr('onclick',onclick);
>
> (setting
Sorry I should have written
$('a').attr('onclick',onclick);
(setting the attribute value not the inner text!)
On Sep 15, 9:09 am, sirrocco wrote:
> Let's say you have a :
>
> asd
>
> I want to get the onclick text in a variable - something like
>
> var onclick = $('a').attr('onclick');
>
> The
You will need to use the text() attribute to do this.
so, once you do:
var onclick = $('a').attr('onclick');
You then place it where you want this way:
$("a").text(onclick);
However, if you have several links on a page it will be better to
assign it to an id. Plus, since "onclick" is a javasc
9 matches
Mail list logo