Like, I want to check if a link has a certain domain, or already has parameters attached to the end.
is there a way of doing a regex thing like ~= maybe?
currently, I have
alert(ref);
$j("a[href*='mysite']").each(function(i){
alert("hello");
$j(this).attr('href',$j(this).attr('href') + "?ref=" + $j.cookie.get("tb_ref"));
});
but the selector isn’t working. (I never see the Hello alert, but I seed the alert ref alert.
my a tags
<a href="http://domain.mysite.com/">yeah, link</a>
<a href="http://google.com/">g, link</a>
Use the substring/contains selector:
$("selector[name*='mystring']")finds attribute name=”somemystring”
If you’re looking for the whole word, delimited by spaces, then use the whole word selector:
$("selector[name~='mystring']")finds attribute name=”some mystring is good”
EDIT I took your code from above and created a jsFiddle for it. I see the one ‘Hello’ alert pop-up. (I didn’t do an alert for the
alert(ref), as I didn’t know whatrefwas.) So the selector works for yourhrefattributes. You’re alising jQuery different than normal (normal =$, you’re using$j). Did you register this alias properly? If you use$orjQueryinstead, does your code work then?