Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: selector question (selecting by onclick attribute)

i'm having this markup:

<a href='#' onclick='loadpage(121);'>
<a href='#' onclick='loadpage(122);'>
<a href='#' onclick='loadpage(123);'>

my question: how can i select the 2nd link object by jQuery using the id 122? i've tried something like $("a[onclick=loadpage(122)]") but didn't work.

thx

like image 428
Fuxi Avatar asked Aug 19 '10 02:08

Fuxi


2 Answers

Try adding in the ; and placing the loadpage(122); in single quotes.

Try it out: http://jsfiddle.net/PQB5U/

$("a[onclick='loadpage(122);']")​
like image 143
user113716 Avatar answered Sep 18 '22 22:09

user113716


All these ways works. Use the one whichever fits your need.

$('a[onclick="loadpage(122);"]')​ // match entire onclick value
$('a[onclick^="loadpage(122)"]')​ // match from the left of onclick value
$('a[onclick*="loadpage(122)"]')​ // match anywhere in onclick value
like image 43
Kim Avatar answered Sep 20 '22 22:09

Kim