there’s a php scripts which create multiple <p>text</p> elements due to user’s query.
I’d like to create an option that every time user clicks on a certain element , the text in this elements will appear in a text box.
The intuitive way to do such task is:
<p class="c1"> textA...</p>
<p class="c2"> textB...</p>
<p class="c3"> textC...</p>
<p class="c4"> textD...</p>
and the jQuery code will be :
$("p.c1").click(function(){ code... }
$("p.c2").click(function(){ code... }
etc ...
Is there any elegant method of implementing this functionality ?
Any suggestion will be helpful,
Thanks in advance
you can assign multiple classes to HTML elements. You can change your PHP script to output mutliple classes. i.e.
Then you can use the click function.
JSFIDDLE