Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery check if starts with for a link

I have the following in my .delegate:
link_id is the id of the link. I need to next say if that id started with RPwd then do something. Why doesn't ^= work in this case?

    var link_id = $(this).attr('id');  //capture the id of the clicked link
    if (link_id ^= "RPwd") {
like image 962
Nate Pet Avatar asked Feb 04 '26 08:02

Nate Pet


2 Answers

The starts with ^= selector is a jQuery object selector. You're doing a string comparison, and can therefore use indexOf()

if (link_id.indexOf("RPwd") === 0) {
   // Match
}
like image 95
Michael Berkowski Avatar answered Feb 05 '26 21:02

Michael Berkowski


As far as I know ^= is not an operator in javascript. That could be your problem.

I think you are looking for

if ($(this).is('[id^="RPwd"]')) {
}
like image 37
JohnFx Avatar answered Feb 05 '26 20:02

JohnFx