Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:11:16+00:00 2026-06-17T19:11:16+00:00

I have this simple jQuery snippet (very simple with jQuery) and I want to

  • 0

I have this simple jQuery snippet (very simple with jQuery) and I want to convert this to javascript which seems to be really hard.

For example, I have no idea what to do with the .each – function.

Hope you can help, give me a hint or solve the problem quickly.

 $("#rTab div[id^=tab]").each(function(){
     if( !$.trim( $(this).html() ).length ) {
         id = $(this).attr("id");
     //alert(id);
         $("#rTab li[rel="+id+"]").hide();
     } 
 });

$(".tabContent").hide();
$(".tabContent:first").show(); 

//click MUSS live
$("ul.tabs li").live('click',function() {
$("ul.tabs li").removeClass("active");
$(this).addClass("active");
$(".tabContent").hide();
//MUSS rel, weil href mit location.hash in product.php so nicht läuft
var activeTab = $(this).attr("rel"); 
$("#"+activeTab).fadeIn(); 
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:11:18+00:00Added an answer on June 17, 2026 at 7:11 pm

    Here you go:

    each("#rTab div[id^=tab]",
        function(element){
            if(element.innerHTML.trim().length > 0) {
                id = element.getAttribute("id");
                //alert(id);
                each("#rTab li[rel="+id+"]",
                    function(element){
                        element.style.display = 'none';
                    }
                );
            } 
        }
    )
    
    each("#rTab li[rel="+id+"]",
        function(element){
            element.style.display = 'none';
        )
    );
    each(".tabContent:first",
    function(element){
            element.style.display = 'block';
        )
    );
    
    each("ul.tabs li",
        function(element){
            element.addEventListener(
                'click',
                function(e) {
                    e = e || window.event;
                    each("ul.tabs li",
                        function(e){
                            e.setAttribute('class' e.getAttribute('class').replace("active",''));
                        }
                    e.target.setAttribute('class' e.getAttribute('class') + "active");
    
                    each(".tabContent",
                        function(element){
                            element.style.display = 'none';
                        )
                    );
                    var activeTab = e.target.getAttribute("rel"); 
    
                    //$("#"+activeTab).fadeIn(); 
                    // I'm not going to write a loop to fade in a element.
                }
            );
        }
    );
    
    
    function each(selector, func){
        var e = document.querySelectorAll(selector);
        if(e.forEach){
            e.forEach(func);
        }else{
            for(var i = 0, l = e.length; i < l; i++){
                func(e[i]);
            }
        }
    }
    

    It’s more code, yes. The problem is that all those jQuery selectors can return multiple elements, so it’s a loop for every selector. Hence the alias to make that slightly shorter.

    At least this should give you an idea of how things work in native JS. Please note that the querySelectorAll isn’t supported on older browsers, and forEach is IE 9+.

    Also, in the .style.display = 'none'; and .style.display = 'block';, you may want to cache the old display value somehow, since not all elements use block as default display setting.

    An alternative to

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this very simple jQuery function: $(.milestone-in-tree).live({ mouseenter: function() { setTimeout( $.ajax({ type:
I have this simple function: <script type=text/javascript> //<![CDATA[ jQuery(function($){ function here(b){alert(b);} ; here(6); });
I have a simple jquery flipcard animation - http://jsfiddle.net/gGAW5/36/ Now the way this flip
I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},
I'm new to jQuery so this may be a real simple answer. I have
really simple question, just having a hard time actually making it work. I have
I have a really simple snippet of code and a really (probably) simple change
I have this simple piece of code : int a = 1, b =
I have this simple code (for making things shorted, the important bits are probably
I have this simple redirection on my website and it does not rewrite my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.