- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9321 Articles for Object Oriented Programming
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
300 Views
Use the addEventListener() method to attach an event handler.ExampleYou can try to run the following code to learn how to work with addEventListener() method in JavaScript − Double click the below button. Double Click document.getElementById("btnid").addEventListener("dblclick", displayEvent); function displayEvent() { document.getElementById("pid").innerHTML = Date(); }
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
1K+ Views
To create a new img tag in JavaScript, pass an HTML string to the constructor,var myImg = $(''); $(document.createElement(myImg)); myImg.attr('src', responseObject.imgurl);You can also use the following code to create a new img tag with the attributes like src, id, etc −var myImg = $('', { id: 'id1', src: exampleimg.png', alt: 'Alt text' });
![Shubham Vora](https://www.tutorialspoint.com/assets/profiles/485898/profile/60_1456867-1657516792.jpeg)
8K+ Views
HTML contains special characters such as ‘, ’ ‘/, ’ and many more such as single and double commas. These special characters are used for the HTML tag, such as ‘’ is used to close the HTML tag. This tutorial teaches us to escape HTML special characters in JavaScript.Now, the question is that what if we want to use these characters inside the HTML content? If we use special characters normally in the HTML content, it considers it the opening or closing HTML tag and produces an unknown error.For example, we need to render the below string to the browser. ... Read More
![Abhinanda Shri](https://www.tutorialspoint.com/assets/profiles/13552/profile/60_73264-1512711555.jpg)
494 Views
The isNan() method is used in JavaScript to check whether there’s the existence of an undefined value or can say checks for a NaN object. ExampleTo check whether a JavaScript date is valid or not, you can try to run the following code − var date1, date2; date1 = new Date("2018/1/1"); if( ! isNaN ( date1.getMonth() )) { document.write("Valid date1: "+date1); } else { document.write("Invalid date1"); } date2 = new Date("20181/1"); if( ! isNaN ( date2.getMonth() )) { document.write(" Valid date2: "+date2); } else { document.write("Invalid date2"); } The isNaN(null) == false is semantically correct. This is because null is not NaN.
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
116 Views
Try any of the following for the width of the image you want to create −myImg.setAttribute('width', '5px');OrmyImg.width = '5';OrmyImg.style.width = '5px';You can also try the following code to add the width and height to the background image −var myImg = new Image(5,5); myImg.src = 'http://www.example.com';
![Vrundesha Joshi](https://www.tutorialspoint.com/assets/profiles/13566/profile/60_88163-1512715024.jpg)
1K+ Views
To get only the else part, just negate, using ! the operator in JavaScript. You can try to run the following code to achieve this −var arr = {}; if (!(id in arr)) { } else { }In addition, if you want the existence of a property in an object, then use hasOwnProperty −if (!arr.hasOwnProperty(id)) { } else { }
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
493 Views
Use the keydown event in JavaScript to get to know which keys are pressed at once. The following is the script −Examplevar log = $('#log')[0], keyPressed = []; $(document.body).keydown(function (evt) { var li = keyPressed [evt.keyCode]; if (!li) { li = log.appendChild(document.createElement('li')); keyPressed [evt.keyCode] = li; } $(li).text(Key Down: ' + evt.keyCode); $(li).removeClass('key-up'); }); $(document.body).keyup(function (evt) { var li = keyPressed [evt.keyCode]; if (!li) { li = log.appendChild(document.createElement('li')); } $(li).text('Key Up: ' + evt.keyCode); $(li).addClass('key-up'); });