How do I make this jQuery text disappear?

后端 未结 3 1406
逝去的感伤
逝去的感伤 2021-01-24 15:43

So I\'m a student and just very lost in my coding class. My teacher gave us this code to make it so when I click on a header, it expands into a paragraph.

He then wants

相关标签:
3条回答
  • 2021-01-24 15:53
    function  toggleArticle(id){
    ($('#'+id).is(':visible') ? $('#'+id).hide() : $('#'+id).show() )}
    
    0 讨论(0)
  • 2021-01-24 16:08

    Just use jQuery's toggle.

    $('#'+headerId).on('click', function(){
        $('#'+id).toggle();
    });
    
    0 讨论(0)
  • 2021-01-24 16:10

    If you are using js and not jquery

    var visible = false;
    function showArticle(id) {
      if (visible === false) {
        document.getElementById(id).style.display="block";
        visible = true;
      }
      else {
        document.getElementById(id).style.display="none";
        visible = false;
       }
     }
    
    0 讨论(0)
提交回复
热议问题