Get elements within a div with PHP / Laravel

0

I wanted to know if it would be possible to have several elements inside a div using Laravel or PHP, for example:

<div>
<a class="elemento">Elemento 1</a>
<a class="elemento">Elemento 2</a>
<a class="elemento">Elemento 3</a>
</div>

Obtain the values of those 3 elements and introduce them in an array to then make a query to a database. The intention is that a user can add or delete (by clicking on them) that data by choosing from a list, from the list they go to this div so that they can visualize what they have selected, and then take those values and use them with the base of data.

Thanks and best regards.

    
asked by Viturbiko 03.05.2018 в 20:26
source

1 answer

0

Look at my next example:

var tuArray = [];

function getElement(element){
  var text = element.textContent;
  tuArray.push(text);
  console.log(tuArray);
}

/*
Luego cuando tengas que enviar estos datos deberás enviarlos con ajax
https://www.w3schools.com/xml/ajax_intro.asp
*/
<div>
<a class="elemento" onclick="getElement(this); return false;">Elemento 1</a>
<a class="elemento" onclick="getElement(this); return false;">Elemento 2</a>
<a class="elemento" onclick="getElement(this); return false;">Elemento 3</a>
</div>

You could try something of this, tell us how it went.

Greetings!

    
answered by 03.05.2018 в 22:13