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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:11:48+00:00 2026-05-25T03:11:48+00:00

$(function(){ $(‘.tab2’).live(‘click’, function() { $(‘#coverTextH3’).text(data[1].H3) $(‘#coverTextP’).text(data[1].P) }); }); Lets say I have a link

  • 0
$(function(){
    $('.tab2').live('click', function() {
      $('#coverTextH3').text(data[1].H3)
      $('#coverTextP').text(data[1].P)
        });
           });

Lets say I have a link <a href="www.link.com"></a> How do I pass data, the index of an array, to a jQuery function so I do not have to repeat my code, for each index [0]-[7]?

 var data = [
    {
        H3: 'name',
            p: 'more'

    },
    {
        H3: 'string',
        p: 'more strings'
     }]
  • 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-25T03:11:49+00:00Added an answer on May 25, 2026 at 3:11 am

    There are numerous options. If attaching handlers via javascript, I would select basing on element’s id or some custom attribute, not the class. So say you have a number of links like this:

    <a href="#" class="tab1" link-number="1">Tab 1</a>
    <a href="#" class="tab2" link-number="2">Tab 2</a>
    <a href="#" class="tab3" link-number="3">Tab 3</a>        
    

    javascript in this case would be

    $(function(){
        $('a[link-number]').live('click', function() {
            var index = $(this).attr('link-number') * 1 - 1;
            $('#coverTextH3').text(data[index].H3)
            $('#coverTextP').text(data[index].P)
        });
    });
    

    Alternatively, you can attach click handlers right in your a elements declaration:

    <a href="#" class="tab1" onclick="setCover(0)">Tab 1</a>
    <a href="#" class="tab2" onclick="setCover(1)">Tab 1</a>
    <a href="#" class="tab3" onclick="setCover(2)">Tab 1</a>
    

    and define setCover function like this:

    function setCover(index) {
        $('#coverTextH3').text(data[index].H3)
        $('#coverTextP').text(data[index].P)
    }
    

    Each of alternatives require changes in your htlm. If for some reason it is not possible, you need to at least now the range of your tabs, which can be quite tricky.

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

Sidebar

Related Questions

function exporttoexcel() { $('#export').click(function() { $.ajax({ url: 'exportdata.aspx', cache: false, success: function(data) { }
function drawLabel(labelsIndex) { // Check not deleted Label data:(DBID, text, styling, x, y, isDeleted)
function holiday_hitlist($tablename, $hit_user){ global $host, $user, $pass, $dbname; $link = mysql_connect($host, $user, $pass, $dbname);
function json (url){ $.getJSON(url, function(data) { return data; }) } this function don't see
function redirect($url){ header(HTTP/1.1 303 See Other); header(Location: $url); exit(); } I have the function
function twitterify($ret) { $ret = preg_replace(#(^|[\n ])([\w]+?://[\w]+[^ \\n\r\t< ]*)#, \\1<a href=\\\2\ target=\_blank\>\\2</a>, $ret); $ret
function addFav(id){ $.ajax({ url: misc/favAdd.php, type: POST, data: { mode: 'ajax', user: id}, dataType:
function appendRefToLinks(ref){ alert(hi); $j('a').each(function(i){ alert('hello'); $j(this).attr('href',$j(this).attr('href') + ?ref= + $j.cookie.get(tb_ref)); }); } I see
function getMainContent(ID, num, lang){ $.ajax({ type: POST, url: WebMethods.aspx/showMain, data: '{AID: ' + articleID+
function msg ($msg) { echo <script type='text/javascript'>alert('$msg');</script>; } if (count($_POST)) { msg('TEST!!!!!'); } <!DOCTYPE

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.