use this
jQuery(this).prop('href', '#');
or
jQuery(el).prop('href', '#');
Pregunta
I validate image path whether it is image path or some other path. If it is the image then replace the particular href value to #
But the # value is affected all links. How can i replace the image link to #
jQuery(document).ready(function($) {
$("a").each(function(i, el) {
var href_value = el.href;
if (/\.(jpg|png|gif)$/.test(href_value)) {
jQuery('a').prop('href', '#');
}
});
});
Here is the
Any Suggestion would be great.
Solución
use this
jQuery(this).prop('href', '#');
or
jQuery(el).prop('href', '#');
Otros consejos
Try with this
like this
jQuery(document).ready(function($) {
$("a").each(function() {
var href_value = $(this).attr('href');
if (/\.(jpg|png|gif)$/.test(href_value)) {
jQuery(this).prop('href', '#');
}
});
});
The reason all links get their href set to # is that you use jQuery('a').prop('href', '#'); when you find an image link. jQuery('a') finds all a-tags in the entire page.
Try using your el variable instead. Something like:
if (/\.(jpg|png|gif)$/.test(href_value)) {
jQuery(el).prop('href', '#');
}