Register for your free account! | Forgot your password?

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

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

Advertisement



e.target Attributes Problem

Discussion on e.target Attributes Problem within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
Cc_Cc_Cc's Avatar
 
elite*gold: 0
Join Date: Mar 2011
Posts: 422
Received Thanks: 17
e.target Attributes Problem

Guten Tag,

ich habe viele Beiträge und unter jedem Beitrag kann man kommentieren oder ein Bild posten. Wenn ich jetzt ein Bild posten möchte klicke ich auf das Foto-Symbol (In Html:


Jedes Foto-Symbol hat ein Attribute namens: Data-Attr-Id. Dort wird die Beitrag ID gespeichert. Ich möchte jetzt beim betätigen des Foto-Symbols die Beitrag ID des Foto-Symbols bekommen.

Wenn ich jetzt auf den ersten Beitrag draufklicke, zeigt er mir es an wunderbar. Aber wenn ich jetzt nach unten scrolle zeigt er mir die Beitrag ID Des ersten Beitrages an. Egal welches Symbole ich klicke , es wird immer die gleiche Beitrag ID angezeigt obwohl jedes Data-Attribute eine andere Beitrag ID hat.

JS:


Weiß jemand woran es liegt?
Cc_Cc_Cc is offline  
Old 02/09/2020, 01:28   #2


 
False's Avatar
 
elite*gold: 0
The Black Market: 243/0/0
Join Date: Apr 2011
Posts: 11,115
Received Thanks: 2,436
Bitte stell mal ein laufendes Beispiel zur verfügung, das erleichtertet das helfen deutlich ! (Dafür kannst du z.b. jsfiddle nutzen).

Wenn du eh schon Jquery nutzt, kannst du übrings
Code:
var id = $(e.target).data("attr-id');
statt
Code:
var id = e.target.getAttribute('data-attr-id');
nutzen
False is offline  
Old 02/09/2020, 02:26   #3
 
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 167
I think the problem is because he's loading dynamic content when scrolling down, but new content won't work with already registered listeners, so in order to make them work u should add a listener to your new elements, the fast way to do it is remove current class listener and register it again after adding the new content
elmarcia is offline  
Old 02/09/2020, 12:02   #4


 
False's Avatar
 
elite*gold: 0
The Black Market: 243/0/0
Join Date: Apr 2011
Posts: 11,115
Received Thanks: 2,436
Quote:
Originally Posted by elmarcia View Post
I think the problem is because he's loading dynamic content when scrolling down, but new content won't work with already registered listeners, so in order to make them work u should add a listener to your new elements, the fast way to do it is remove current class listener and register it again after adding the new content
I dont think this is the problem. If that would the problem he would get no id, instead of the same id.
Also he wouldnt need to remove the listener and add it again, he could use
Code:
$('body').on('eventName', 'targetSelector', function)
instead of
Code:
$('targetSelector').on('eventName', function)
False is offline  
Old 02/10/2020, 09:02   #5
 
lnqlorlouz's Avatar
 
elite*gold: 0
Join Date: Jun 2013
Posts: 405
Received Thanks: 84
Liegt es nicht daran, dass immer das erste gefundene Element den Eventlistener bekommt?
Also müsstest du nicht so etwas in der Art machen:
Code:
   var inputs = document.querySelectorAll(".inputfile2comment");
   inputs.forEach(input => {
     input.addEventListener("change", e => 
        console.log(e.target.getAttribute("data-attr-id");
   });
lnqlorlouz is offline  
Old 02/10/2020, 20:05   #6


 
False's Avatar
 
elite*gold: 0
The Black Market: 243/0/0
Join Date: Apr 2011
Posts: 11,115
Received Thanks: 2,436
Quote:
Originally Posted by lnqlorlouz View Post
Liegt es nicht daran, dass immer das erste gefundene Element den Eventlistener bekommt?
Also müsstest du nicht so etwas in der Art machen:
Code:
   var inputs = document.querySelectorAll(".inputfile2comment");
   inputs.forEach(input => {
     input.addEventListener("change", e => 
        console.log(e.target.getAttribute("data-attr-id");
   });
Nein, wenn wenn es mehrere Elemente für den Selector gibt, dann bekommen alle das Event.
(Sofern man Jquery nutzt => Was er tut)
False is offline  
Old 02/12/2020, 17:25   #7
 
lnqlorlouz's Avatar
 
elite*gold: 0
Join Date: Jun 2013
Posts: 405
Received Thanks: 84
Quote:
Originally Posted by False View Post
Nein, wenn wenn es mehrere Elemente für den Selector gibt, dann bekommen alle das Event.
(Sofern man Jquery nutzt => Was er tut)
Stimmt, da war was. Ich arbeite zum Glück nicht mit jQuery. Die meisten Sachen gehen heutzutage auch so ziemlich einfach, dank Babel und alle neuen Dinge ab ES5.

Ich denke der Threadersteller hat schon eine Lösung(?), falls nicht, bräuchten wir mehr Code oder du setzt mal ein debugger Statement.
lnqlorlouz is offline  
Reply


Similar Threads Similar Threads
Target self / Target enemy ? >.>
03/21/2011 - General Gaming Discussion - 2 Replies
Well, i just looked through all the existing rose-hack-threads (not that any of them would work...), when i saw those "Levelbots" with a "Target self" and a "Target Enemy" Skill :o Well, my question is: Where can i find this Skill? O_o I´m playing AruaRose, but i neither got it from beginning nor being able to buy it anywhere :o Well, it would be nice if u could tell me... :> Edit: Oh, and if one of the Maker of those "Rose online Privatserver"-Threads should read this, would you...
WoW Hide My Target - Hide your target!
10/24/2010 - WoW Exploits, Hacks, Tools & Macros - 46 Replies
Voerst: Hier geht es um einen kleinen Hack, um euer Target zu verstecken. Andere werden euer aktuelles Target nicht mehr sehen. Dieser kleine Hack ist aus Langeweile entstanden, wenn ihr ihn also unnütz findet, steht es euch frei diesen Thread ohne jeglichen noch sinnloseren Kommentar zu verlassen, danke! Wie funktioniert der Hack? Code der verändert wrid in WoW: 00518E07 - 5 Bytes (0x90, 0x90, 0x90, 0x90, 0x90) 00524311 - 5 Bytes (0x90, 0x90, 0x90, 0x90, 0x90) 00528306 - 5 Bytes...
[Help] Invalid Target/Cannot find Target(ZSZC)
05/29/2010 - SRO Private Server - 4 Replies
Some write they have Problems with ZSZC SRO-DB, by mobs for example "Ishade/Penon/Ujigi(lvl50-56)", in the Textbox right side down a message: "Invalid Target" or " Cannot Find Target", All have this Problem, a good message, i have the solution! You need Use SRO-DB Bot V0.8 and NOT V0.9a! +++Use this and you will have Fun by Botting+++



All times are GMT +2. The time now is 11:14.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

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