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 7582617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:28:43+00:00 2026-05-30T18:28:43+00:00

Anyone jQuery experts here can help me convert the follwing javascript codes to jQuery?

  • 0

Anyone jQuery experts here can help me convert the follwing javascript codes to jQuery? Although it works I’d rather see hows it’s done with jQuery

function loadit(element)
{
    document.getElementById('container').src = element.rel;
    var tabs = document.getElementById('tabs').getElementsByTagName("a");

    for (var i=0; i < tabs.length; i++)
    {
        if(tabs[i].rel == element.rel) 
        {
            tabs[i].className = "selected";
        }
        else
        {
            tabs[i].className = "";
        }
    }
}

Here is the HTML

    <div id="tabs"> 
              <ul> 
                <li><a href="#" rel="/root/a" onClick="loadit(this)" class="selected">A</a></li>
                <li><a href="#" rel="/root/b" onClick="loadit(this)">B</a></li>
                <li><a href="#" rel="/root/c" onClick="loadit(this)">C</li> 
              </ul> 
         </div>
<iframe id="container" name="container"></iframe>

And here is how I populate the container on windowload:

function startit()
{
    var tabs = document.getElementById('tabs').getElementsByTagName("a");
    document.getElementById('container').src = tabs[0].rel;
}

window.onload=startit;
  • 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-05-30T18:28:44+00:00Added an answer on May 30, 2026 at 6:28 pm

    Assuming the parameter passed in (element) is itself a jQuery object, it could look like this.

    Note that where ii’m dealing with a jQuery object, I tend to prefix the variable with $ to distinguish it

    function loadit($element)
    {
        var rel = $element.prop('rel');
        $('#container').prop('src',rel);
        $('#tabs a').each(function(){
            var $a = $(this);
            $a.toggleClass('selected',$a.prop('rel') == rel);
        });
    }
    

    edit: I noticed a typo in my code above. I was missing a # from the line

    $('#tabs a').each(function(){
    

    Here is a very simplified live example in lieu of your HTML: http://jsfiddle.net/FKf9L/1/

    Ive assumed that you’re calling loadit when clicking one of the a‘s which form the tabs. If this is the case it’s a bit redundant, you should just latch onto the click event of the a in jQuery. Making the code:

    $('#tabs a').click(function(){
       var $this = $(this);
       var rel = $this.attr('rel');
       $('#container').prop('src',rel);
       $this.siblings().removeClass('selected');
       $this.addClass('selected');
    });
    

    See this live example: http://jsfiddle.net/p99Q2/

    edit2: You may as well do away with the startit method and just issue a click on the first a within the tabs:

    $(document).ready(function(){
        $('#tabs a').click(function(){ 
            ...
        });
    
        $('#tabs a:first').click();
    });
    

    Live example: http://jsfiddle.net/p99Q2/2/

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

Sidebar

Related Questions

Possible Duplicate: Generate a Hash from string in Javascript/jQuery Can anyone suggest a simple
Anyone knows if with jquery or general javascript, I can change the referrer from
Can anyone see why jQuery isn't working in IE8 mode (from F12 developer tools)
Does anyone know of a jquery plugin that can make a thumbnail of an
Can anyone tell the jQuery code for automatic refreshing of a page? i am
Does anyone know if jQuery can handle an animation like: rgba(0,0,0,0.2) → rgba(0,255,0,0.4) I
Can anyone suggest good jquery tooltip to show brief details for small part. i
Does anyone know of any jQuery plugins that can achieve the scrolling effect like
Does anyone know the jQuery equivalent for window.document.write('') in javascript? Thanks
here's a gimme for anyone that knows jQuery: I have a navigation <ul class=nav>

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.