VISHAL MAHAJAN

Learn Java Coding From Digital Marketing Agencies in Bangalore

WEBVTT Now you might notice some kind of weird behavior with our current implementation which is you know if you click for a planet let me refresh click for a planet. Works and you might expect because we're adding cumulatively to. H.M. we should be able to click again and it should add another planet. But as you see it doesn't happen. And I just want to show you something. Let's see Learn java Coding From Digital Marketing agencies in Bangalore and Correct. So theoretically every time we click on my button the event listener gets triggered and it invokes this callback function. So we should theoretically see clicked every time we click that button let's see a click once we see it did run the event listener but I click again. And that's weird it's not running this time.

And the reason for that is and it's kind of a weird quirk is that when you append or add to each you know basically any assignment interrupts UML, unfortunately, causes destruction of the child elements. And that means you know it also destroys the event listener which is kind of weird. So it destroys reference to the event listener so it's not getting triggered anymore. So a couple of ways that we could solve that. Digital agency And then we get rid of this console log. Actually no. I'll leave it there for now. But a couple of ways we could solve this. Whoa, that doesn't happen.

You know we if we don't decide to interface him out it's not going to remove those child elements essentially. So one thing we could do it's kind of a compromise but we could do something like this so Konst my div equals if we use the dorm functions document or create element div like so and then that's when we remove references to div and Planetes div for example and then instead of just doing it for each team we say my div thought increase Chimo equals planet div and then we do and append child on the original div ID. Right. So actually I think I called the original one my to do. So let's call this one my planet it's a planet pariah.

OK. So my div inner every two miles of my planet Planet give close planet para. And now we can do my div dot append child. So this is nondestructive. And we just append a planet div right. This will work it's kind of a mishmash right so we're kind of constructing some Digital marketing agencies in Bangalore elements by a string and we're also just using a dom function here to create an element. Let's see if that works. If we click we get our quick message and we see the end or click again and we can see that it did function so click did trigger. If I scroll down I can see that now I can add more planets.

That works as intended but there is a simpler in my view anyway way to do this and it's a bit more intuitive so you know what. Let me undo what I just did. And I do want to put the div inside the string. Ok cool. So we can use an alternative method which is you know to get rid of this line of code as well which is insert adjacent HMO which is pretty cool. So let's try that out here. So do my div referencing, of course, this Konst Daut inserts adjacent it's TNL. Now you tell it in the string where you want to insert it. So we can say before and this is built in there before and there are other ones we can take a look at Digital marketing agencies in Bangalore. But basically, we say before the end and also what we want to insert.

So we want to insert our planet div here so we can do Planet div. So this is nondestructive won't destroy our event listeners. And let's try to. I think this is more intuitive. Personally, Maybe you prefer the other way. And hey that's totally up to you. So let's refresh this let's see if it's working here. Quick cool quick. There we go. So just an alternate way of doing that. But I think this is pretty cool Digital Marketing agencies in Bangalore. And just to play around with some of these other options that we have before and we have after begun for example or before begin let's see what this does quick interesting.

So it's before the beginning of the div... Right. And it just puts it on the very top. What about if we did. But what is actually what we did before begin. Let's see. Maybe hard to tell but it basically Digital Marketing Agencies in Bangalore. If we inspect the element or it's so here's our dear planet and now we're putting the div in front of that so we're not putting it inside the div at all or putting it beforehand. When we did after begin let's see what that does in terms of our dorm. Quick. So this one we have a divided planet and it puts it before the button. So before the rest of our content begins here's our half planet. It's pretty cool stuff. What about something like. After And and let's see.

As you can imagine this will add it after the end. So this creates a separate. It's not a child of div now it's just a separate div. So being a new use case these are going to be pretty useful I think. So this Digital Marketing Agencies in Bangalore end and just kind of puts them in the order you call them in the pretty neat right. So it definitely pays to know these dorm functions. And another thing that kind of bothers I am that there's no karma here when it's a really long number you know in English we tend to put a comma after there are three other languages might put a dot.

  • Love
  • Save
    Add a blog to Bloglovin’
    Enter the full blog address (e.g. https://www.fashionsquad.com)
    We're working on your request. This will take just a minute...