August 31, 2012

jquery selector contains equals sign

Question by John Buckwell

I am using a jQuery selector to check for characters in href:

var param = "something";
$("a[href*="+param+"]").css("color", "red");

This works fine until “something” contains an = sign. Eg:

var param = "xkey=123";
$("a[href*="+param+"]").css("color", "red");

then I get no result. Anyone know a solution?

Answer by Starx

It is behaving that way becuase, at the end it will translate to ambiguous selector i.e. $("a[href*=xkey=123]") which indeed is invalid.

Escape the equal sign with \ infront and wrap the parameter part with a quote

var param = "xkey\=123";
$("a[href*='"+param+"']").css("color", "red");
April 5, 2012

Is there a reason not to use <=> (null safe equals operator) in mysql instead of =?

Question by cellige

MySql provides a nice operator <=> that works with comparisons that could contain a null such as null <=> null or null <=> 5 etc giving back intuitive results as many programming languages. Where as the normal equals operator always just returns null, which catches many new MySql users such as myself awry.

Is there a reason MySql has both and not JUST the functionality in <=> ? Who really needs an operator that is effectively undefined with built in language types?

Answer by Starx

Is there a reason MySql has both and not JUST the functionality in <=>
?
The operators are completely different from each other.

<=> performs an equality comparison like the = operator, but returns 1 rather than NULL if both operands are NULL, and 0 rather than NULL if one operand is NULL.

Who really needs an operator that is effectively undefined with built
in language types?

This depends on case, just because you haven’t encountered such cases, does not mean nobody needs it.

...

Please fill the form - I will response as fast as I can!