Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 11:27

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



JS Remove Option

Discussion on JS Remove Option within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
MaLLaH95's Avatar
 
elite*gold: 0
Join Date: Dec 2014
Posts: 106
Received Thanks: 16
JS Remove Option

Hallo, Com
ich will mit Javascript doppelte Einträge entfernen, auf Stack Overflow habe ich ein Script gefunden was mit Option funktioniert.
Ich habe jetzt allerdings ein Problem, ich will keine Option benutzen und wollte Fragen, ob einer mir eventuell helfen kann?

<a class="dropdown-item" data-chat-filter="" data-select="TEST" href="#">TEST</a>
3 sollen gelöscht werden weil 4 gleiche vorhanden sind und 1 Soll bleiben
(mithilfe einer id oder den Namen/Value TEST)

Code:
                                <div class="dropdown mr-2">
                                    <button class="btn btn-outline-default dropdown-toggle" type="button" data-chat-filter-list="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                                        All Chats
                                    </button>
                                    <div name="company" class="dropdown-menu" style="overflow: auto;max-height: 400px;">
                                        <a class="dropdown-item" data-chat-filter="" data-select="all-chats" href="#">All Chats</a>
                                        <a class="dropdown-item" data-chat-filter="" data-select="TEST" href="#">TEST</a>
                                        <a class="dropdown-item" data-chat-filter="" data-select="TEST" href="#">TEST</a>
                                        <a class="dropdown-item" data-chat-filter="" data-select="TEST" href="#">TEST</a>
                                        <a class="dropdown-item" data-chat-filter="" data-select="TEST" href="#">TEST</a>
                                        <a class="dropdown-item" data-chat-filter="" data-select="TEST2" href="#">TEST2</a>
                                        <a class="dropdown-item" data-chat-filter="" data-select="TEST3" href="#">TEST3</a>
                                    </div>
                                </div>
Code:
var usedNames = {};
$("select[name='company'] > option").each(function () {
    if(usedNames[this.text]) {
        $(this).remove();
    } else {
        usedNames[this.text] = this.value;
    }
});
MaLLaH95 is offline  
Old 09/22/2020, 14:31   #2
 
lnqlorlouz's Avatar
 
elite*gold: 0
Join Date: Jun 2013
Posts: 405
Received Thanks: 84
Mir war langweilig, hier eine von mehreren Lösungen:
Code:
        const data = document.querySelectorAll("a[data-select]");
        const uniqueElements = [];
        data.forEach(el => {
            if (uniqueElements.find(element => element.getAttribute("data-select") === el.getAttribute("data-select"))) {
                el.remove();
            } else {
                uniqueElements.push(el);
            }
        });
Wenn du auf jQuery stehst, kannst du es auch so machen:
Code:
var usedNames = {};
        $("a[data-select]").each(function () {
            if (usedNames[this.text]) {
                $(this).remove();
            } else {
                usedNames[this.text] = this.getAttribute("data-select");
            }
        });
Damit du nächstes mal weißt, wonach du suchen musst, um dein jQuery Skript umzuschreiben:
-
-

Btw. würde ich sowas eigentlich auf Serverseite prüfen, ob nicht schon ein Eintrag vorhanden ist. Wenn du Zugriff auf die Datenbank hast, kannst die Spalte einfach UNIQUE machen.
lnqlorlouz is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
(HELP) CHANGING UI OPTION TO ADD Auto Target Setting Option
06/05/2018 - RF Online - 0 Replies
Guys, pls help me... i play rf on private server, but this server dont have Auto Target Setting at Option Setting. Pls help me to change UI option from this : http://i.epvpimg.com/uyW6fab.jpg Become this UI option : http://i.epvpimg.com/qUx2eab.png In other word, i need to patch AUTO TARGET t from PATRON*to GOLDEN MYSTERY*patch Sorry for my bad english....
SEARCH FIFA TRAINER with 99 OVR option + option BOT ( auto )
10/09/2016 - Fifa - 24 Replies
I search a automatic FIFA TRAINER and a trainer with 99 OVR option
[Request Help] Remove mobs / remove eur items / remove npc
02/15/2013 - SRO Private Server - 0 Replies
Iam sure all now saies this guy is mad :D why not remove the db i want to know how i can remove mobs from samrkand and add alex mobs there and remove eur item from npc and drobs and remove some npcs ty guys _________________________ I see that there is too much help here it's my topic no.2 without any answer
Remove blue option on item
10/10/2011 - SRO Private Server - 2 Replies
i want to remove either astral, steady, luck or immortal options on my la chest nova +7 which has adv exilir +2 because i wanted to add mp+ but it's impossible as it already has 9 blue options, anyhow to remove one of option above?
Petition To Remove DK evoltion off Dont remove it
01/08/2011 - Dekaron Private Server - 12 Replies
Ex dev of AG dekaron is working with Dekaron Evo. Which he posted the of AG selling a Autovoter which the dev from AG has been fire for over a month!!! also everything is edited off the autovoter that SexyBitch released Photoshop anyone!!!! and Han 911Hacker owner of dekaron evolution posted the petition!!!!!!!!! Top100 Autovote link: New Page 1 this is translated IP 74.52.31.2 THe IP of that adress is the same as Dekaron Evolutions LoginServer IP in Housten Texas!!!!!!!!!!!!!!!!!!!!!!!...



All times are GMT +1. The time now is 11:30.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.