Leave a hide element with javascript

1

I have an element with ID="not1" which is a link to inserted news headlines being dynamically created with the respective news of each title as shown below.

<div id="noticia">
     <div id="not1"><a href="<?php $noticia['idp_postjauport'] ?>"><?php print $noticia['tit_postjauport'] ?></a></div>
     <div class="col-md-12" id="col-md-12">
     <?php print $noticia['pos_postjauport'] ?>
     </div>

     </div> 
     </p>

I have a javascript that should display the contents of my link only when I click on it, javascript below.

    <script type="text/jscript">

$("#not1").click(function(event){
      event.preventDefault();

      $("#col-md-12").hide('slow');

      $("#col-md-12").show(3000);
      event.preventDefault();
    });
});

    </script>

What's happening is that my html page is bringing this open element, but if I click the link it closes and opens again ... I do not know how to fix this little problem

    
asked by anonymous 25.06.2017 / 05:24

2 answers

1

You should have CSS that hides this link. So it is hidden the moment it is created.

You can have CSS in the file .css of the page

#col-md-12 {display: none;}

or inline when the link is created. If you create the link with JavaScript, just make el.style.display = 'none'; before from it being inserted into the DOM.

    
25.06.2017 / 10:35
1

You need to add a statement in javascript to hide the contents of the link as soon as the page starts. As you are using jQuery, this can be done with the following function:

$(document).ready({
   $("#col-md-12").hide();
});
    
25.06.2017 / 06:26