Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Firstly I would like to apologise if this is off topic. I am unsure if it is, as the code written works fine.

Just wondering how I might convert this to JavaScript from JQuery? The code below expands a menu on click like an accordion but I am trying to rewrite this in JS for practise.

( function( $ ) {
$( document ).ready(function() {
$('#accordianMenu > ul > li > a').click(function() {
  $('#accordianMenu li').removeClass('active');
  $(this).closest('li').addClass('active'); 
  var checkElement = $(this).next();
  if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
    $(this).closest('li').removeClass('active');
    checkElement.slideUp('normal');
  }
  if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
    $('#accordianMenu ul ul:visible').slideUp('normal');
    checkElement.slideDown('normal');
  }
  if($(this).closest('li').find('ul').children().length == 0) {
    return true;
  } else {
    return false;   
  }     
});
});
} )( jQuery );
share|improve this question

put on hold as off-topic by Jamal Mar 16 at 0:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
This is off-topic, but you should probably start by reading what each of the jQuery functions do on the jQuery documentation section of their website. – Quill Mar 16 at 0:07
    
This is not off-topic (assuming the current code works)! Not using jQuery might improve performance and will (slightly) improve bandwidth-usage . – Ivan Modric Mar 16 at 13:56

Browse other questions tagged or ask your own question.