+ 3

show/hide button

Hi! I tried to write a JS program where the user can hide/show an element: https://code.sololearn.com/WBLzlnMpAV5Q/?ref=app But this code seems so long for such a simple action. Do you know any better ways for this?

18th Mar 2017, 6:06 PM
Ltzu
Ltzu - avatar
4 Respostas
0
Learn some Jquery! with just these lines of code: $(function () { $('#b').click(function() { $('#e').toggle(500); $('#b').text('switch'); }); }); it's possible to get the same result you that got there. Also, don't forget to use CSS to make the elements have more effect and look better.
18th Mar 2017, 7:07 PM
Welliton Malta
Welliton Malta - avatar
+ 4
use jQuery instead. XD
18th Mar 2017, 6:54 PM
Mario L.
Mario L. - avatar
+ 1
jQuery to toggle the button as well. :) $(document).ready(function(){ $("#b").click(function(){ $("#e").toggle(); if ($(this).text() == "Show") $(this).text("Hide") else $(this).text("Show"); }); })
18th Mar 2017, 7:20 PM
Martian1oh1
Martian1oh1 - avatar
0
Oh, i forgot to tell. I learned ithe basic just a few days ago, and trust me, it looks confusing at first, but after you understand how it works, it must make everything simpler haha
18th Mar 2017, 7:13 PM
Welliton Malta
Welliton Malta - avatar