Why can't I get this to work??
$("a").each(function() {
if ($(this[href$="?"]).length()) {
alert("Contains questionmark");
}
});
Ps.: This is just at simplifyed example, to make it easier for you to get an overview.
You could just outright select the elements of interest.
$('a[href*="?"]').each(function() {
alert('Contains question mark');
});
http://jsfiddle.net/mattball/TzUN3/
Note that you were using the attribute-ends-with
selector, the above code uses the attribute-contains
selector, which is what it sounds like you're actually aiming for.
$("a").each(function() {
if (this.href.indexOf('?') != -1) {
alert("Contains questionmark");
}
});
use this
$("a").each(function () {
var href=$(this).prop('href');
if (href.indexOf('?') > -1) {
alert("Contains questionmark");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With