What Java Script can do? Java Script can change the HTML element, HTML Element contents, style and attribute values. Java Script finds the HTML element by many methods. Most frequently used method is ‘getElementById()’ method.
In previous chapter of Java Script we have learnt that what Java Script is and taken the brief introduction of what can Java Script do?

Now we are going to study more descriptively that what Java Script can do and how?

What Java Script can do?


Java Script can change the HTML element, HTML Element contents, style and attribute values. Java Script finds the HTML element by many methods. Most frequently used method is ‘getElementById()’ method.

getElementById() method


In this method Java Script find the HTML element by their ‘id’ attribute value. For example


<p id = "test"></p>
<script>
  document.getElementById('test').innerHTML = 'Hello World!';
</script>

Note : Java Script accepts both single quotes (‘ ’) and double quotes (“ “).

Java Script can Hide and Show the HTML elements


Java script can hide the HTML elements and show the elements as well by changing the element style (CSS). So we can also say that Java script can change the style of HTML elements.

This is how you can hide the HTML element.


<p id = 'test'>This paragraph is not displayed on the web page if you click below button.</p>
<button onclick = "document.getElementById('test').style.display = 'none';">Hide</button>

And this is how you can show the hidden element.


<p id = 'test'>This paragraph is not displayed on the web page if you click below button.</p>
<button onclick = "document.getElementById('test').style.display = 'block';">Show</button>

Note: You must be familiar with CSS to understand above example.

Java Script can change the value of attribute


Java script can change the value of HTML element attribute. In below example image source is change by Java Script function.


<button onclick = "document.getElementById('myImg').src = 'raincloud.png'">Rainy</button>
<img src = "cloud.png" width = '60%' id = "myImg" onclick = "cloud()">
<button onclick = "document.getElementById('myImg').src = 'cloud.png'">Sunny</button>

Java Script can Add or Remove the HTML elements


Java Script can add and remove the HTML elements. Check the example how to add the HTML element using java script.


<div id = "test">
  <p>Click the below button to create a new paragraph.</p>
</div>
 <button onclick = "createlem()">Create</button>
 
 <script>
  function createlem(){
   var para = document.createElement('p');
   var text = document.createTextNode('This is new paragraph.');
    para.appendChild(text);
   var elem = document.getElementById('test');
    elem.appendChild(para);
  }
 </script>

This is how Java Script can remove HTML element.


<div id = "elem_parent">
<p id = "elem_childe">Click the below button to remove existing paragraph.</p>
</div>
<button onclick = "delelem()">Remove</button>
 <script>
  function delelem(){
   var elem_parent = document.getElementById('elem_parent');
   var elem_childe = document.getElementById('elem_childe');
   
   elem_parent.removeChild(elem_childe);
  }
 </script>


progrramers-logo

progrramers

Hello friends! Progrramers is a tutorial site of w3 programming. If you like this tutorial site please encourages us by sharing this site links with your friends and nears & dears who want to learn web development and give us like on our Facebook page. If have any question please type in to comment box or send us message on social media sites via below given social links. Thank you, have a nice learning.

Post A Comment:

50 comments:

  1. Well, I have got the best information from here the site is fully stuffed with the knowledgeable information.
    additional reading

    ReplyDelete
  2. Hey, thanks for this great article I really like this post and I love your blog and also Check machine learning course in hyderabad at 360DIGITMG.
    360Digitmg machine learning course in hyderabad

    ReplyDelete
  3. Wow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though. 数据分析代写

    ReplyDelete
  4. When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your. Javascript Commission Bot Review

    ReplyDelete
  5. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work. Howtodoninja

    ReplyDelete
  6. This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work. send a fax from an email address

    ReplyDelete
  7. I am Patrice, a front-end web developer built on the coasts of Mauritius island.
    I have 8 years of experience in the industry and the creation of websites has no secrets for me. Web development is a passion that I'm living to the fullest I have created over 300 websites in my career. "Digitalmonstr." is the nickname I use around the web. By my dedication and optimism through my work, I idealize that my clients will mark their presence on the cyberspace as giants. You will be able to beneficiate of the exceptional prices of Mauritius island which are consequently less than a traditional web agency while getting the same expertise
    (I have worked for various web agencies throughout my career)
    href="http://digitalmonstr.com

    ReplyDelete
  8. Thanks, foг ones marvelous posting! I genuinely enjoyed reading it, you miggһt Ƅe a great author. I wiⅼl made certain to booҝmark your blog and ѡill often come back sometime soon. I want to encoᥙrage yourself to continue your great job, have a nice evening!
    Web Development Course
    best web development courses
    web development classes
    web development course near me
    Web Development Training
    training on web development
    web development training program
    web development training course
    web development summer training

    ReplyDelete
  9. I don’t suppose many of websites give this kind of information. SEO Agency Calgary

    ReplyDelete
  10. Very good written article. It will be supportive to anyone who utilizes it, including me. Keep doing what you are doing – can’r wait to read more posts. web design in Switzerland

    ReplyDelete
  11. Many have a huge number of records that hold Individual Recognizing Data, PII, or insightful property that may incorporate licenses, research and unpublished electronic resources. tor links directory

    ReplyDelete
  12. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. can you send a fax from a cell phone

    ReplyDelete
  13. This blog post is really great; the standard stuff of the post is genuinely amazing.
    UX agencies

    ReplyDelete
  14. Promoting a site to increase the number of backlinks, or inbound links, is another SEO tactic.
    offpage SEO
    SEO strength
    SEO ranking

    ReplyDelete
  15. Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. Protocol

    ReplyDelete
  16. Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors.
    web developer near me

    ReplyDelete
  17. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. I will create 65 niche relevant blog comment nofollow seo backlinks

    ReplyDelete
  18. Personally I think overjoyed I discovered the blogs. Niche SEO Backlink

    ReplyDelete
  19. I really like your article. It’s evident that you have a lot knowledge on this topic. Your points are well made and relatable. Thanks for writing engaging and interesting material. backlinks

    ReplyDelete
  20. Obviously I like your web site, but you have to take a look at the spelling on quite a few of your posts. Several of them are rife with spelling problems and I find it very bothersome to inform you. Nevertheless I will surely come again again! Niche relevant OffPage Backlinks

    ReplyDelete
  21. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. download trafficize

    ReplyDelete
  22. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! Take me to another useless website

    ReplyDelete
  23. Aside from changes made to the organization site, the supposition that is regularly that the organization and, in the event that it is utilizing one, its SEO administration, has zero authority over what shows up in web crawler results.SEO Services

    ReplyDelete
  24. Thank you so much for the post you do. I like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. Hummelstown Marketing

    ReplyDelete
  25. We build websites that produce impact and results. Our designers work with you until we've found a design you're happy to call your own. business to business web design

    ReplyDelete
  26. i never know the use of adobe shadow until i saw this post. thank you for this! this is very helpful. sviluppo sito ecommerce

    ReplyDelete
  27. Wow, excellent post. I'd like to draft like this too - taking time and real hard work to make a great article. This post has encouraged me to write some posts that I am going to write soon. sites like fiverr com

    ReplyDelete
  28. Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. sayapro bin checker

    ReplyDelete
  29. The web development lifecycle (WDL) is a more explicit minor departure from the overall system for building up any application development project. Webdesign Genk

    ReplyDelete
  30. For the excellent company Begin with the internet site, the customer service over the cell phone, to the detailed care they deliver in your presence
    leather jacket

    ReplyDelete

  31. Thanks for sharing this post.
    This article really useful for me and I learn a lot of things from this blog.
    I am in the process of working as a freelance mean stack developer

    ReplyDelete
  32. I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. HTML Tutorial

    ReplyDelete
  33. This is my first time visit to your blog and I am very interested in the articles that you serve. Provide enough knowledge for me. Thank you for sharing useful and don't forget, keep sharing useful info: pay monthly web design

    ReplyDelete
  34. I?¦m now not sure where you are getting your information, however great topic. I needs to spend some time finding out more or understanding more. Thanks for great information I used to be looking for this info for my mission. visit this web-site

    ReplyDelete
  35. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. SEO Service Provider

    ReplyDelete
  36. The web hosting companies provide a share of disk space and available bandwidth to a customer for a monthly fee. Once the customer is signed up, they can upload files to their personal space on the web server and the information is then viewable to anyone interested on the Internet. web hosting

    ReplyDelete
  37. At the point when you need reasonable web facilitating for your private venture. ESIT web facilitating has a lot of brilliant highlights to bring to the table. https://zenradius.com

    ReplyDelete
  38. Its for these reasons it happens to be improved that anyone can helpful test earlier than building. It will be possible to write more piece of writing like this. Graphics Design

    ReplyDelete
  39. Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading. hire freelance python developers

    ReplyDelete
  40. On the off chance that your planner comprehends web optimization and plans for web based promoting during the plan stage your webpage will see huge profits from your interest in method of traffic and client transformations. Web Design Manchester

    ReplyDelete
  41. I simply want to tell you that I am new to weblog and definitely liked this blog site. Very likely I’m going to bookmark your blog . You absolutely have wonderful stories. Cheers for sharing with us your blog. homepage

    ReplyDelete
  42. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work. Pyramid Analytics

    ReplyDelete
  43. I am incapable of reading articles online very often, but I’m happy I did today. It is very well written, and your points are well-expressed. I request you warmly, please, don’t ever stop writing. dofollow blog comment

    ReplyDelete
  44. This programming language is very helpful for developers and through this, they can make different softwares and earn a lot of money. You should learn JavaScript and make your future bright. Coursework writing service.

    ReplyDelete
  45. Great articles and great layout. Your blog post deserves all of the positive feedback it’s been getting. https://hostinglelo.in/

    ReplyDelete
  46. There's Amazon Drive, which offers limitless record stockpiling for just $59.99 dollars each year. As of late, they additionally procured the real time site jerk, the biggest computer game live stream site there is giving Amazon portion of the overall industry in the streaming and e-sports ventures. web development services in pakistan

    ReplyDelete
  47. I cannot wait to dig deep and kickoff utilizing resources that I received from you. Your exuberance is refreshing. https://hostinglelo.in/

    ReplyDelete
  48. I think this is an informative post and it is very beneficial and knowledgeable. Therefore, I would like to thank you for the endeavors that you have made in writing this article. All the content is absolutely well-researched. Thanks... dark0de market

    ReplyDelete
  49. It is quite beneficial, although think about the facts when it reaches this target. seo

    ReplyDelete