Hi Andy,

Sorry. There is no need to use the find() method.

function linkClick() {
 var target = $('#test').attr('href');
 window.location = target;
}

---------------------------------------------------

But I strongly recommend do not use javascrit whitin the markup.
Keep behavior inside its own layer.

So a best approach should be:

Markup layer
<div id="linktest"">Emulating click</div>

Behavior layer:
$(document).ready(function(){
$('#linktest').click(function() {
 var target = $('#test').attr('href');
 window.location = target;
});
});





-----Mensagem Original----- De: "Andy789" <e...@abcstudio.com.au>
Para: "jQuery (English)" <jquery-en@googlegroups.com>
Enviada em: sábado, 31 de janeiro de 2009 05:15
Assunto: [jQuery] Triggering a link with no click event



HI All,

It could be a silly question, but I cannot find a simple answer...

I need to trigger a link with href via an external function, i.e.

<div onclick="linkClick()">Emulating click</div>
<a id="test" href="flash/pdfs/test.html" >my link</a>

function linkClick(){
$("#test").click();

}

It does not work and returns nothing. I understanbd that it is because
the a#test does not have the actual onclick event. So, how can I
emulate click on a#test?

Note, that I cannot modify the a link element or add onclick events.

Reply via email to