Click here to Skip to main content
15,882,163 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi Experts,

I am just starting to learn JavaScript. And I'm currently working on a project that only JavaScript is accepted. The project is to toggle multiple buttons and have found the code solution for this but it's in jQuery. It's working fine... Demo is at[^]

But I need the code function written in JavaScript instead of jQuery. Can anyone help me how to convert this jQuery function into JavaScript code?

Thank you!


    // INT
    // the height of the highest one
    var highestlanguage = 0;

    // get highest language so it will not scroll up.
    var _gethighestlanguage = function () {
        var _height = jQuery(this).height();
        if(highestlanguage<_height) {
            highestlanguage = _height;

    // It's not a "real toggle". Just close all and slide down the one
    var _togglelanguage = function(){
        var _target = jQuery(this).data('target');

    // close the nearest element with the class "language". So don't use it in these boxes again
    var _closelanguage = function () {

    // Get highest language

    // Assign height to the container. (Prevents page from up-scrolling on close)
    jQuery(".container").css("min-height", highestlanguage + "px");

    // Hide All

    // Assign functions to the buttons

1 solution

Why? Do you really understand that jQuery is also Javascript? So you cannot reasonably mention "only JavaScript is accepted"; this is totally irrelevant; in all cases, we discuss Javascript and nothing else.

So, instead of eliminating jQuery, why not, for example, putting it on the site. It would not mean "installing" anything. jQuery is just put on the site in exact same way your Javascript (you are discussing in your question) is put.

So, there is no "conversion"; it sounds just like nonsense. Likewise, "Javascript instead of jQuery" is nonsense. Please start with understanding of this point. If, by some weird reason, you want to eliminate jQuery (why?!), just don't use it (but why asking this question then?). What's the problem? You don't know how to hide and show the element, slide it, and so on? Then learn it from the documentation and ask your particular questions if you face some problems (please don't expect that someone does your work for you; we usually don't do it). Just do the job (but why doing this job if it is already done for you in jQuery?!).

How else? You know what, if you have nothing else to do, just look at jQuery code. All the answers to your questions are there. Or some other code. :-)

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900