Jquery eq() toggle all elements












0















I'm using eq to get only a specific div, when I click on the "X" I should close the div specified. But what happens is that when I click on eq 0 it closes eq 1 and 2, and when I click on the div from eq 1 it closes eq 2. What can be happening?



$('.' + tabHistoryBtn).eq(0).click(function() {
$('.' + currentDivTabBarContent).eq(0).remove();
$('.' + tabHistory).eq(0).remove();
});

$('.' + tabHistoryBtn).eq(1).click(function() {
$('.' + currentDivTabBarContent).eq(1).remove();
$('.' + tabHistory).eq(1).remove();
});

$('.' + tabHistoryBtn).eq(2).click(function() {
$('.' + currentDivTabBarContent).eq(2).remove();
$('.' + tabHistory).eq(2).remove();
});









share|improve this question

























  • We need more context into how these bindings are being generated. Given that the variable is "tabHistoryBtn", my first thought was that you are keeping some sort of breadcrumb of the users interactions or something, in which case tab 3 was at one point tab 2, which was also at some point tab 1, and so on. And it's possible you're binding these methods each time you make a new tab history, not unbinding the previous event listeners attached.

    – Taplar
    Dec 31 '18 at 21:15













  • Any link that the user clicks will give a load of php content without reloading the page, and will create tabs to navigate between these contents, in the same function that creates a div where the newly generated content is and the tabs have the function call I want to use the tabs in the tabs, but I can not find the tabs in the tabs, so I can not use them. remove the tab (tabHistory). But every time I click on eq 0 remove 1 and 2, and on 1 remove 2 and 3!

    – Will John
    Dec 31 '18 at 21:46











  • It did not work, here is an example of the code only: jsfiddle.net/willianjohns/w5eLs8d4

    – Will John
    Dec 31 '18 at 22:04











  • I used event.stopImmediatePropagation (); and solved one of my problems, now if I click close it just closes that div. But I discovered another problem, as I call the function of closing the tabs within the function of creating them, when I close for example the div eq 1, the div eq2 is no longer eq2 and yes eq 1, but it does not update, I believe should I change where to call the close tabs function, to update when eq should find them, how should I do this?

    – Will John
    Dec 31 '18 at 22:46











  • Please edit your question to include any important commentary, and include all relevant code. You can use Stack Snippets to include your code in a runnable state, just like jsfiddle.

    – Heretic Monkey
    Jan 1 at 1:45
















0















I'm using eq to get only a specific div, when I click on the "X" I should close the div specified. But what happens is that when I click on eq 0 it closes eq 1 and 2, and when I click on the div from eq 1 it closes eq 2. What can be happening?



$('.' + tabHistoryBtn).eq(0).click(function() {
$('.' + currentDivTabBarContent).eq(0).remove();
$('.' + tabHistory).eq(0).remove();
});

$('.' + tabHistoryBtn).eq(1).click(function() {
$('.' + currentDivTabBarContent).eq(1).remove();
$('.' + tabHistory).eq(1).remove();
});

$('.' + tabHistoryBtn).eq(2).click(function() {
$('.' + currentDivTabBarContent).eq(2).remove();
$('.' + tabHistory).eq(2).remove();
});









share|improve this question

























  • We need more context into how these bindings are being generated. Given that the variable is "tabHistoryBtn", my first thought was that you are keeping some sort of breadcrumb of the users interactions or something, in which case tab 3 was at one point tab 2, which was also at some point tab 1, and so on. And it's possible you're binding these methods each time you make a new tab history, not unbinding the previous event listeners attached.

    – Taplar
    Dec 31 '18 at 21:15













  • Any link that the user clicks will give a load of php content without reloading the page, and will create tabs to navigate between these contents, in the same function that creates a div where the newly generated content is and the tabs have the function call I want to use the tabs in the tabs, but I can not find the tabs in the tabs, so I can not use them. remove the tab (tabHistory). But every time I click on eq 0 remove 1 and 2, and on 1 remove 2 and 3!

    – Will John
    Dec 31 '18 at 21:46











  • It did not work, here is an example of the code only: jsfiddle.net/willianjohns/w5eLs8d4

    – Will John
    Dec 31 '18 at 22:04











  • I used event.stopImmediatePropagation (); and solved one of my problems, now if I click close it just closes that div. But I discovered another problem, as I call the function of closing the tabs within the function of creating them, when I close for example the div eq 1, the div eq2 is no longer eq2 and yes eq 1, but it does not update, I believe should I change where to call the close tabs function, to update when eq should find them, how should I do this?

    – Will John
    Dec 31 '18 at 22:46











  • Please edit your question to include any important commentary, and include all relevant code. You can use Stack Snippets to include your code in a runnable state, just like jsfiddle.

    – Heretic Monkey
    Jan 1 at 1:45














0












0








0








I'm using eq to get only a specific div, when I click on the "X" I should close the div specified. But what happens is that when I click on eq 0 it closes eq 1 and 2, and when I click on the div from eq 1 it closes eq 2. What can be happening?



$('.' + tabHistoryBtn).eq(0).click(function() {
$('.' + currentDivTabBarContent).eq(0).remove();
$('.' + tabHistory).eq(0).remove();
});

$('.' + tabHistoryBtn).eq(1).click(function() {
$('.' + currentDivTabBarContent).eq(1).remove();
$('.' + tabHistory).eq(1).remove();
});

$('.' + tabHistoryBtn).eq(2).click(function() {
$('.' + currentDivTabBarContent).eq(2).remove();
$('.' + tabHistory).eq(2).remove();
});









share|improve this question
















I'm using eq to get only a specific div, when I click on the "X" I should close the div specified. But what happens is that when I click on eq 0 it closes eq 1 and 2, and when I click on the div from eq 1 it closes eq 2. What can be happening?



$('.' + tabHistoryBtn).eq(0).click(function() {
$('.' + currentDivTabBarContent).eq(0).remove();
$('.' + tabHistory).eq(0).remove();
});

$('.' + tabHistoryBtn).eq(1).click(function() {
$('.' + currentDivTabBarContent).eq(1).remove();
$('.' + tabHistory).eq(1).remove();
});

$('.' + tabHistoryBtn).eq(2).click(function() {
$('.' + currentDivTabBarContent).eq(2).remove();
$('.' + tabHistory).eq(2).remove();
});






javascript jquery removechild






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 21:17









MTCoster

3,77122141




3,77122141










asked Dec 31 '18 at 21:13









Will JohnWill John

167




167













  • We need more context into how these bindings are being generated. Given that the variable is "tabHistoryBtn", my first thought was that you are keeping some sort of breadcrumb of the users interactions or something, in which case tab 3 was at one point tab 2, which was also at some point tab 1, and so on. And it's possible you're binding these methods each time you make a new tab history, not unbinding the previous event listeners attached.

    – Taplar
    Dec 31 '18 at 21:15













  • Any link that the user clicks will give a load of php content without reloading the page, and will create tabs to navigate between these contents, in the same function that creates a div where the newly generated content is and the tabs have the function call I want to use the tabs in the tabs, but I can not find the tabs in the tabs, so I can not use them. remove the tab (tabHistory). But every time I click on eq 0 remove 1 and 2, and on 1 remove 2 and 3!

    – Will John
    Dec 31 '18 at 21:46











  • It did not work, here is an example of the code only: jsfiddle.net/willianjohns/w5eLs8d4

    – Will John
    Dec 31 '18 at 22:04











  • I used event.stopImmediatePropagation (); and solved one of my problems, now if I click close it just closes that div. But I discovered another problem, as I call the function of closing the tabs within the function of creating them, when I close for example the div eq 1, the div eq2 is no longer eq2 and yes eq 1, but it does not update, I believe should I change where to call the close tabs function, to update when eq should find them, how should I do this?

    – Will John
    Dec 31 '18 at 22:46











  • Please edit your question to include any important commentary, and include all relevant code. You can use Stack Snippets to include your code in a runnable state, just like jsfiddle.

    – Heretic Monkey
    Jan 1 at 1:45



















  • We need more context into how these bindings are being generated. Given that the variable is "tabHistoryBtn", my first thought was that you are keeping some sort of breadcrumb of the users interactions or something, in which case tab 3 was at one point tab 2, which was also at some point tab 1, and so on. And it's possible you're binding these methods each time you make a new tab history, not unbinding the previous event listeners attached.

    – Taplar
    Dec 31 '18 at 21:15













  • Any link that the user clicks will give a load of php content without reloading the page, and will create tabs to navigate between these contents, in the same function that creates a div where the newly generated content is and the tabs have the function call I want to use the tabs in the tabs, but I can not find the tabs in the tabs, so I can not use them. remove the tab (tabHistory). But every time I click on eq 0 remove 1 and 2, and on 1 remove 2 and 3!

    – Will John
    Dec 31 '18 at 21:46











  • It did not work, here is an example of the code only: jsfiddle.net/willianjohns/w5eLs8d4

    – Will John
    Dec 31 '18 at 22:04











  • I used event.stopImmediatePropagation (); and solved one of my problems, now if I click close it just closes that div. But I discovered another problem, as I call the function of closing the tabs within the function of creating them, when I close for example the div eq 1, the div eq2 is no longer eq2 and yes eq 1, but it does not update, I believe should I change where to call the close tabs function, to update when eq should find them, how should I do this?

    – Will John
    Dec 31 '18 at 22:46











  • Please edit your question to include any important commentary, and include all relevant code. You can use Stack Snippets to include your code in a runnable state, just like jsfiddle.

    – Heretic Monkey
    Jan 1 at 1:45

















We need more context into how these bindings are being generated. Given that the variable is "tabHistoryBtn", my first thought was that you are keeping some sort of breadcrumb of the users interactions or something, in which case tab 3 was at one point tab 2, which was also at some point tab 1, and so on. And it's possible you're binding these methods each time you make a new tab history, not unbinding the previous event listeners attached.

– Taplar
Dec 31 '18 at 21:15







We need more context into how these bindings are being generated. Given that the variable is "tabHistoryBtn", my first thought was that you are keeping some sort of breadcrumb of the users interactions or something, in which case tab 3 was at one point tab 2, which was also at some point tab 1, and so on. And it's possible you're binding these methods each time you make a new tab history, not unbinding the previous event listeners attached.

– Taplar
Dec 31 '18 at 21:15















Any link that the user clicks will give a load of php content without reloading the page, and will create tabs to navigate between these contents, in the same function that creates a div where the newly generated content is and the tabs have the function call I want to use the tabs in the tabs, but I can not find the tabs in the tabs, so I can not use them. remove the tab (tabHistory). But every time I click on eq 0 remove 1 and 2, and on 1 remove 2 and 3!

– Will John
Dec 31 '18 at 21:46





Any link that the user clicks will give a load of php content without reloading the page, and will create tabs to navigate between these contents, in the same function that creates a div where the newly generated content is and the tabs have the function call I want to use the tabs in the tabs, but I can not find the tabs in the tabs, so I can not use them. remove the tab (tabHistory). But every time I click on eq 0 remove 1 and 2, and on 1 remove 2 and 3!

– Will John
Dec 31 '18 at 21:46













It did not work, here is an example of the code only: jsfiddle.net/willianjohns/w5eLs8d4

– Will John
Dec 31 '18 at 22:04





It did not work, here is an example of the code only: jsfiddle.net/willianjohns/w5eLs8d4

– Will John
Dec 31 '18 at 22:04













I used event.stopImmediatePropagation (); and solved one of my problems, now if I click close it just closes that div. But I discovered another problem, as I call the function of closing the tabs within the function of creating them, when I close for example the div eq 1, the div eq2 is no longer eq2 and yes eq 1, but it does not update, I believe should I change where to call the close tabs function, to update when eq should find them, how should I do this?

– Will John
Dec 31 '18 at 22:46





I used event.stopImmediatePropagation (); and solved one of my problems, now if I click close it just closes that div. But I discovered another problem, as I call the function of closing the tabs within the function of creating them, when I close for example the div eq 1, the div eq2 is no longer eq2 and yes eq 1, but it does not update, I believe should I change where to call the close tabs function, to update when eq should find them, how should I do this?

– Will John
Dec 31 '18 at 22:46













Please edit your question to include any important commentary, and include all relevant code. You can use Stack Snippets to include your code in a runnable state, just like jsfiddle.

– Heretic Monkey
Jan 1 at 1:45





Please edit your question to include any important commentary, and include all relevant code. You can use Stack Snippets to include your code in a runnable state, just like jsfiddle.

– Heretic Monkey
Jan 1 at 1:45












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53991456%2fjquery-eq-toggle-all-elements%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53991456%2fjquery-eq-toggle-all-elements%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas