• Learn Java Programming online by Digital Marketing Companies in Delhi

    WEBVTT So show an example of you know a situation where you might care about the data attribute we could check if there's kind of a population for example and then we could do styling conditional on that. So what I mean by that is we can say data Daut population equals and you know what again we can just kind of pass it population OK. So now each of these will have a data population field and just as a sanity check I will make sure that is the case population. OK. So we can kind of check this and then style these to kind of highlight the uncarpeted planets just as a simple example. Learn Java Programming online by Digital Marketing Companies in Delhi So let's do something like this for the highlights button ID equals I later show unpopulated planets or highlight on a populated planet. I like. OK. And then we can just kind of do a function here. Function and let's see you know we'll attach an event listener first to that button. So phones later equal document get element by ID. I later dot add event listener quick show on populated you lead to. OK, so function shows unpopulated. So, first of all, we can say all planets Oh planet did equal document dot queries selector or we're looking for all of that Digital Marketing Companies in Delhi have the class. Class of planet Caylus will create a node list which means we can do a loop. So as you can see loops superpowerful stuffier so will say prop of our planet divs. And the way we can access the data set is well you can just grab it because this is going to give us all the did.


    So if we want to access the class for example. So cancel that log Propp just to take a quick peek at it. Let's take a look see if we show you the digital Marketing Company And this is all of our kids right so we can get the class if we want to. And so if we wanted to console log prop dot data set dot population. So this is how you can access it in Javascript From Digital marketing companies in Delhi. So this should show us what the population is for each of these each of them does have this data attribute to refresh multiple planets highly. Here you see they all have a population attribute. There's a couple of unknowns though right which means we can just check proper Digital Marketing companies in Delhi set that population equals unknown. Well, what we can do is we can say Propp thought style thought background color equals yellow or so this is a pretty good use case for accessing the data attribute read it doesn't really affect anything. We don't need to keep track of it really but it is important for us in our javascript because we want to be able to snatch that out. And unlike an ID which each would have unique, you know a couple of them will have an unknown field on it. So it kind of makes sense to use the dataset attribute for this type of situation. Let's see what happens if we try to show what Watto planets highlight. OK, right away we can see that there is a couple of Digital Marketing Companies in Delhi and it only applied the logic to those ones. We could, of course, have done it a different way we could have done it with C Ss in which case we would maybe toggle a different class. So let's try it out. Let's say Daut highlight and with the background color yellow K, that's our CSSA close this tab.


    That's not going to go anywhere just in the background. And then we can say Propp dot. Class list toggle yellow OK let's see if this works as intended. Boom Boom. OK, it didn't work. And oh I didn't call it yellow. I called it highly. OK. Let's try it again refresh shall multiple highlights. Aha. Now we can again Digital Marketing Companies in Delhi Boom boom boom boom boom. Pretty cool. A little bit of a tangent but I did want to mention that this data actually can be pretty useful. OK so, first of all, we will say value and we can grab the target if we do something like this. We don't target value it so as a sanity check, as usual, your Consolo get to eat at target value let's refresh open a console. Gate change we should get. Unknown. Awesome work. Medium-low. OK. So that's working as intended. We're accessing the target's value of whatever target we are on in our selector, therefore, we can actually snatch that out. Konst value equals event target value but we structured it. Now we can basically write this function appear to be more reusable therefore we can say for Konst of all planet divs which will have been updated by the time we run this highlight function or not and if not just won't do anything. OK so here we can check Propp dot data set that population is equal to the value that we snatch out from the selector well, in that case, we can say Propp thought well the style here style that background equals Teale.


    I think that's a pretty start where the color This should be all we need to get it to work. Let's try to get closer. So let's get the planets. Let's try Digital Marketing Companies Delhi. Unknown haha. Success right so with just a couple lines of code by using this data attribute on the population we are able to access that match that against the value of something else and we can really see how we can write concise and reusable code here right. One issue though is that if we switch to say a high population it doesn't remove the style from the other targets. And you know that's very simple to fix. We'll just do for every loop through we'll just remove the stat background color so we can say prompt that style of background equals white for example. So every loop through they'll all get the style set to white and then the ones that match will get them set to Teall so that should cure that slight issue. Now let's get the planets we can say. UNKNOWN OK let's check out the low population success medium. OK, we have a couple of medium three medium ones. And finally the high