I have a N-O, the number of such items on the page:
& lt; div class = "main" & gt;
& lt; a class = "text" & gt; any text & lt; / a & gt;
& lt; div class = "buttons" & gt; buttons & lt; / div & gt; // This element is hidden by default.
& lt; / div & gt;
I need to press when
& lt; a class = "text" & gt; any text & lt; / a & gt;
Showed Div Buttons. And only the one in this block Main.
I found an exemplary scriptor and slightly snapped , but the problem is that it opens the buttons of all items.
How to change it?
1, Authority 100%
Another option that works exactly in chrome:
$ (". text"). Click (function () {
$ (this) .ClOSEST ('. Main'). Find ('. Buttons'). show ();
});
Update
$ (". text"). Click (function () {
E = $ (this) .Closest ('. Main'). Find ('. Buttons');
if (! E.is (': Visible')) {
$ ('. Buttons'). Hide ();
E.Show ();
}
});
understood like this.
2, Authority 75%
$ (". text"). Click (function () {
$ (this) .next (". Buttons"). show ();
});
3, AUTHORITY 75%
$ (". text"). Click (function () {
$ (this) .next (". Buttons"). Toggle ();
});
will and open and close, as indicated in the title.
4, Authority 50%
& lt; Head & gt;
& lt; script & gt;
If (document.getelementsByclassName) {
GetElementsByClass = Function (ClassList, Node) {
Return (Node || Document) .gelementsByClassName (ClassList)
}
} else {
GetElementsByClass = Function (ClassList, Node) {
var node = node || Document
List = node.getelementsbytagname ('*'),
Length = list.Length,
ClassArray = classlist.split (/ s + /),
Classes = Classarray.Length,
result = [],
I, J.
for (i = 0; i & lt; length; i ++) {
For (j = 0; j & lt; classes; j ++) {
if (list [i] .className.Search ('\\ b' + ClassArray [j] + '\\ b')! = -1) {
Result.Push (List [i])
Break
}
}
}
Return Result
}
}
& lt; / script & gt;
& lt; / Head & gt;
& lt; Body & gt;
& lt; div class = "main" & gt;
& lt; p class = "text" & gt; any text & lt; / p & gt;
& lt; div class = "buttons" & gt; buttons & lt; / div & gt;
& lt; / div & gt;
& lt; p class = "text" & gt; any text & lt; / p & gt;
& lt; script & gt;
Function Fn () {
GetTelementsByclass ('Buttons') [0] .style.Display = 'None'
}
if (document.addeventlistener) {
GetElementsByClass ('Text') [1] .addeventlistener ('Click', Fn, False);
} else {
GetElementsByclass ('Text') [1] .attachevent ('OnClick', Fn)
}
& lt; / script & gt;
& lt; / body & gt;