digital marketing companies in madhapur for learning key events of Javascript
Key Events of Javascript
1. Introduction
a. Another type of event I wanted to discuss key events. So basically you can listen for key down or key up and you can check if a certain key was pressed or not and eat each key has basically a Unicode value including things like on a Mac command and windows control or shift caps lock tab. You know they all have a key code if you want to check that out and do something like document start an event listener do key down to an anonymous function in here digital marketing companies in madhapur and the console that logs key code OK let's see what happens. Refresh this here he'll keep an eye on our console case. I'm going to type it in anywhere. A. So that was the letter A.
b. He says that it has Unicode. Now let's see what B is K. C D E F. And you know it's not really in order that you can make sense of. So probably the best way is just experimenting doing something like this or just look it up online. You know there's a lot of online resources to find out what the key code of any given keypresses. Let's see if I press the spacebar. OK, that's key code and if you want to check digital marketing companies in madhapur 2019 . What about the tab that's key code. What about the number one key code forty-nine. It's not really a logical order. Here's one here's to you for the sometimes it kind of is but usually it's just kind of random Here's enter introduced count as a click I guess. Or rather it counts as.
2. The number and Key Codes
a. You see I don't really have this memorized there's no real reason to memorize these. I just know that they do exist. And like I mentioned before when we're doing preventing the default. So once I minimize the space here it gives me a scroll bar to best internet marketing company so I can actually hit spacebar to kind of scroll bar scroll down and if I didn't want that to happen. Well, we can check the key code so we can say if the key code equals and what was that keycode again looks like it's and we tested out. So if the key code it's not a string it's a number if the key code is.
b. Then we can do either prevent default and you can just kind of do your conditional checks in here. Let's refresh and see if we are now able to scroll via the space bar space. So it's not letting the scroll. So that's actually what I wanted that's what I wanted to do. I could do say all down that still works on my Mac device but now I'm not letting my users score down by space. And again probably not something you want to do because users won't like that. Usually So check here digital marketing companies in madhapur in addition, a key down there's also key up. So let's see here with the key code again. So this is key down. We can also do key up. So an event listener keeps function he console log key code K.
3. A button and Their properties
Let's see here. So I'm holding down the A button. Just keep firing over and over and let go of the A button and it fired a different digital marketing companies in madhapur 2019.So let's see an example of some key down and key up events in action. When would I ever use this? Well, you might use this for example if you're making some kind of site and you want it to show if someone's typing. So maybe there's some kind of textarea and it's a chat or something like that and you just want to be able to update the dorm to tell hey is someone typing yes or no if they show that you know reflect that in the dorm somewhere.
4. IDs To save
Otherwise, remove that after they stop typing. All right so let's remove these event listeners out of div in here. Give I.D. Three. Close that off and in here we can have a p tag that's just going to be empty at first and a text area as well text area. So basically we want to add in when a user is typing. Just put it in the digital marketing companies in madhapur string and here the user is typing right. And if we show this-this is what it would look like. Users typing. And then this is just a text area which the user can resize if they want to. So we could Grabow the value of whatever the user typing in here.
But initially let's just get it to say the user is typing just kind of reflect that for kind of better user experience. And it's actually pretty straightforward to do with one catch that we're going to take a look at. So let's grab this div out of the digital marketing companies in madhapur dorm Konst if three equals document get element by id and we want Div X we can use queries selectors to grab this P and this text area. So conc pair equals Div query selector P so and Conte's textarea equals Div queries selector and we want to query text areas the query selector we want.