0

I'm trying to add this script to my site but there are a list of the same element generated by the script "voucherCode" so am struggling here because when I test it, only the first element will 'reveal' no matter which one is clicked...

  <!--EDIT-->

tried calling the script using a class which works but now all of them reveal:

1 Answers1

0

Like Blazemonger said, browsers will not pick up multiple elements with the same ID. Id should be unique, and if you need something that repeats then uses classes.

Update well first of all you need to add the class instead of ID

<div class="voucherCode">

if you use jquery (call it in the header first, google jquery)

$('.trigger_class').click(function(){
    //do what you need to do here when clicked
    //to access all of the voucherCode class you use $('.voucherCode').css('display', 'block');
});

Update 2: if you only want specific ones to reveal then you need identifiers on those ones (class(2 or more) or id(only 1)) then target the ones you want to show. To make it more dynamic, you can add a rev or title attribute to the trigger anchor tag, and use jquery to grab that attribute and use it as the element you want to reveal

<a class="trigger_class" rev="reveal_class_or_ID">....</a>

then in the javascript

$('.trigger_class').click(function(){
    //grab the rev from the a, this is use a class (hence the .  if it is using id it would be #)
    $("." + $(this).attr("rev")).css('display','block');
});

Lastly don't forget to add the reveal_class_or_ID to your items

Update:

I am not good with php but it seems like you have the option to add the iterator or index to

<div class="revealVoucher" id="reveal_dynamicID">
    <a href="<?=$affiliate_url?>" target="_blank">Reveal Code</a>
</div>

<div class="voucherCode" id="show_dynamicID">
    <a href="<?=$affiliate_url?>"><?=$voucher_code?></a>
</div>

I don't know how iterator works in php but if you know php this should make sense

Huangism
  • 16,278
  • 7
  • 48
  • 74
  • I have called the script with a class but now all of them 'reveal' – John Ellis May 10 '12 at 15:46
  • just edited my post above, i've used classes this time but need to make it so only element clicked on is revealed not all of them! – John Ellis May 10 '12 at 15:54
  • I don't think I can give each one a unique class because the script only produces the xml instance once in the php file, (as far as i know) I can only wrap one variable. – John Ellis May 10 '12 at 16:10
  • can provide sample code for that, provide at least 2 blocks for reveal. Can't you add a index using php when pulling data out of the xml? something like id="item01" then 02 and so on, if it is unqiue then you can just use IDs – Huangism May 10 '12 at 16:18
  • or supply more sample output from before you made any modification from this place. give at least 2 blocks – Huangism May 10 '12 at 16:19
  • I don't really know php :) will keep trying though, thanks a lot for your help! – John Ellis May 10 '12 at 17:42
  • can i use something like this: [link]http://stackoverflow.com/questions/3416227/create-dynamic-div-with-unique-ids-jquery – John Ellis May 10 '12 at 17:52
  • it's the same idea, currently you have revealVoucher and voucherCode classes for all of your divs, you need to make them something like voucherCode_01 voucherCode_02 etc.. and for revealVoucher you could do the same thing. I would suggest you ask someone who is near you physically with php knowledge. it is really easy to do so anyone who knows php can do it. – Huangism May 10 '12 at 18:43