Pro
114 points
Serious WPMU DEV-ster
I'm helpful
Giovanni
Member — 4th February 2012 (3 months ago)
I am trying to change an IMG tag's SRC value when a button gets clicked. The button is on an iFrame and the IMG tag is on the TOP Document.
Thank you in advance!
My button HTML:
<a href="javascript:void(0)" class="add_featured_btn button-secondary" rel="<?php echo $attach_id;?>">Use as gift image</a>
My IMG HTML:
<img id="hm_uploaded_giftimage" src="" alt="Your Gift" />
I've tried this javascript:::
<script type="text/javascript">
$(".add_featured_btn").click(function(){
$("img#hm_uploaded_giftimage",top.document).attr({ src: 'http://www.ourhoneymoongiftregistry.com/wp-content/uploads/2012/02/IMG_75102-150x150.jpg'});
});
</script>
I've also tried this javascript::::
echo "<script type=\"text/javascript\">
jQuery(\".add_featured_btn\").click(function(){
jQuery(\"hm_uploaded_giftimage\",top.document).setAttribute('src', '". $img_preview . ";');
});
</script>";

Responses (3)
Support Chimp — 4th February 2012 (3 months ago) #
So you want something to happen "onclick". You should look into the JS onclick function for that.
Take care.
Member — 5th February 2012 (3 months ago) #
isn't this utilitizing it?
jQuery(\".add_featured_btn\").click(function(){I am very new at jQuery. Any help would be appreciated.
Thanks,
Giovanni
Support Chimp — 5th February 2012 (3 months ago) #
Not in your code no, but in your wording:
So I presumed you wanted something to happen when something is clicked?
Am I mistaken?
Take care.
Become a member