0
How to choice particular div
Hello Sololearn,it is really hard to explain, i have a lot of divs with simillar class name and diffrent text on it, then button which send this text to another page using innerHTML, but I cant choice particular div when i click button,if I dont misunderstood it could be done with "child".(I dont remember sorry)) P.S:class must be simillar and without Php
7 odpowiedzi
+ 5
Fury, if the div is placed before the button then you can try this script. Map the function to the onclick attribute of the buttons, this will get the button's previous sibling and show it's text in alert window. Elaborate more if I misunderstood your intention.
function showText() {
var o = event.target;
alert(o.previousElementSibling.innerHTML);
}
+ 7
Try to make the classes different so you can differentiate between the divs😉
/ ithink it will help you😉
+ 3
Fury you're welcome, I'm glad if it helps 👍
+ 2
Fury, why don't you share your code link on your question? actually it will help others to understand the problem better by seeing your code.
How do you choose the div from the many divs? do you choose in random? or is there some criteria that defines which div should be selected?
My idea would be to use `getElementsByClassName` or `querySelectorAll` method to collect all the divs having similar class name, and once we have it - we can choose by index. Just an idea : )
+ 2
lpang ,thank you your code works perfectly
+ 1
Try to make the classes different so you can differentiate between the divs😉
/ ithink it will help you😉
no I cant make diffrent class names
i'v written about it