0

I have a link that has an id from a database. When I click on it how can i copy this id to 2 buttons by applying to them the same id ? Behold how i try :

1- <a  class="godown" id="<?=$row->id_apoint;?>"><?=$row->nombre;?></a>
2- <button  class="bill" >button1</button>  <button  class="bill" >button2</button>

JQUERY

$('.godown').click(function() {
var godown = $(this).attr('id');
// How can I copy the variable **godown ** to the buttons so that they have the save id as godown ?
});

Thanks

Diasline
  • 625
  • 3
  • 32
  • 3
    *"...how can i copy this id to 2 buttons by applying to them the same id"* You don't. Having more than one element with the same ID is invalid. This sounds like [an X/Y problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem); why do you think you want to do that? – T.J. Crowder May 15 '18 at 16:41
  • 2
    You **should not** repeat ids. They are meant to be unique by web standards. So how do you do this? The answer is **don't**. https://dom.spec.whatwg.org/#concept-id – Taplar May 15 '18 at 16:42
  • thanks you so much your are right – Diasline May 15 '18 at 16:44
  • **var newItem = $("selector").clone();** this will make a copy of selected tag. Also you can set value an attribute like this; **$(element).attr("attrName","newValue");** – Serhat MERCAN May 15 '18 at 16:45
  • In reality the 2 buttons are hidden, after I click on the link the are appeared. After I click on one of them I need this id to process. – Diasline May 15 '18 at 16:49
  • Possible duplicate of [Does ID have to be unique in the whole page?](https://stackoverflow.com/questions/9454645/does-id-have-to-be-unique-in-the-whole-page) – Taplar May 15 '18 at 16:50
  • You need a class, you should never repeat ids. Classes are intended to be repeated as a method of grouping elements. And you already have a class on them. – Taplar May 15 '18 at 16:51
  • Ok i am going to use class. How can I assign the class of the link to the class of the 2 buttons ? – Diasline May 15 '18 at 16:54

0 Answers0