Onclick on link cause error

Hi,

I installed a Wordpress theme X and on my homepage i wan’t to set an onclick event in the html attribute on multiple link.

but when i click on theses link i get an error like :

Uncaught Error: Syntax error, unrecognized expression: #/

Can you help me ?

Link of my site
http://www.11villars.com/

function i call in the onclick

function changeImage(element) {
    document.getElementById('imageReplace').src = element;
}

Hi There,

Upon checking your website, I couldn’t find any elements with the imageReplace ID.

You can try with this code instead:

jQuery(function($) {
	function changeImage(src){
		$('imageReplace').attr('src', src);
	}
});

Let us know how it goes!

Thanks for your fast reply

I test your code but i have the same error

I forgot to precise, when i’m logged my code works but when i’m logout it’s broke

it’s for this part of my website

and the elements with the imageReplace ID is on the left :slight_smile:

Hi There,

Please remove the <a> tag around your images, wrap them with the <div class="pointer"></div> instead.

Then add this custom JS under X > Theme Options > JS:

jQuery(document).ready(function($) {
	$(".pointer img").on('click touchend', function(event) {
		event.preventDefault();
		var src = $(this).attr('src');
		$('#imageReplace').attr('src', src);
	});
});

Hope it helps :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.