replace SRC inside wordpress
-
Hello everyone!
I’ve researched during this morning, but couldn’t fix the problem, so, if anyone could help, thanks a lot!
I want to replace the atribute src of an image inside wordpress with jquery by clicking on a button, however I can’t.
the image to change SRC
<label for="id1"> <img src="<?php bloginfo( 'template_url' ) ?>/img/main-image.png" /> </label>
the buttons to click
<ul> <li class="bt-color"> <img src="<?php bloginfo( 'template_url' ) ?>/img/blue.png" alt="blue"> </li> <li class="bt-color"> <img src="<?php bloginfo( 'template_url' ) ?>/img/purple.png" alt="purple"> </li> <li class="bt-color"> <img src="<?php bloginfo( 'template_url' ) ?>/img/pink.png" alt="pink"> </li> </ul>
the code on jquery
/* offline code */ $('.bt-color').click(function() { var alt = ($(this).children().attr('alt')); if ( alt === 'blue' ){ $("label[for='id1']").children().attr('src', 'img/main-image-blue.png' ); } else if ( alt === 'purple' ){ $("label[for='id1']").children().attr('src', 'img/main-image-purple.png' ); } }); /* online with wordpress, my failed trial */ jQuery('.bt-color').click(function() { var alt = (jQuery(this).children().attr('alt')); if ( alt === 'blue' ){ jQuery("label[for='id1']").children().attr('src', '<?php bloginfo( 'template_url' ) ?>/img/main-image-blue.png' ); } else if ( alt === 'purple' ){ jQuery("label[for='id1']").children().attr('src', '<?php bloginfo( 'template_url' ) ?>/img/main-image-purple.png' ); } });
offline doing with html for tests works perfectly, however not on wordpress. Am I doing something wrong?
Thanks a lot!
- This topic was modified 3 years, 8 months ago by .
- This topic was modified 3 years, 8 months ago by . Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘replace SRC inside wordpress’ is closed to new replies.