简体   繁体   中英

Turning a div that includes a ul with a hidden li list from HTM to JS

SO I'm practicing my JS skills and would like to turn my HTML completely or almost completely into JS. I would like to focus on creating these elements and making them work.

 var main = function() { $(document).ready(function () { $('.recipePicContainer').click(function () { $(this).next('.recipes').toggle("slow").toggleClass('selected'); }); }); }; $(document).ready(main); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="mainContainer col-md-12 col-xs-12"> <div class="checkBoxes"> <span class="recipePicContainer"> <img class="recipe" src="../images/grasshopper-cocktail.jpg" alt="Cocktail"> <div>Cocktail</div> </span> <ul class="recipes"> <li class="ingredient"><input type="checkbox"> ingredient 1</li> <li class="ingredient"><input type="checkbox"> ingredient 2</li> <li class="ingredient"><input type="checkbox"> ingredient 3</li> <li class="ingredient"><input type="checkbox"> ingredient 4</li> <li class="instructions">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li> </ul> </div> </div> 

ok, here's the checkbox part figured out:

 $('<input type="checkbox" value="1" />').prependTo(".ingredients");

still need some help with the loop. anyone?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM