saravanabawa
saravanabawa

Reputation: 1777

jquery multiple different id with a variable

How to use multiple different id with a variable of ID value? It don't show any error or output

function show_div(id)
{
    $("#edit_li"+id, "#save_li"+id).show();
}

Upvotes: 2

Views: 174

Answers (4)

Mohan Kumar
Mohan Kumar

Reputation: 102

function show_div(id)
{
    $("#edit_tag"+id+",#save_li"+id).show();
}

The variable to be placed between + , while using within string.

Upvotes: 2

madalinivascu
madalinivascu

Reputation: 32354

Always append and prepend your variables with + when they are in a string

function show_div(id)
    {
        $("#edit_tag"+id+",#save_li"+id).show();
    }

Upvotes: 1

Adil
Adil

Reputation: 148120

You need to put , in selector as well as the comma outside mean you have two parameters in the selector instead of separating ids in selector.

$("#edit_tag"+id  ", #save_li"+id).show();

Upvotes: 1

Pranav C Balan
Pranav C Balan

Reputation: 115222

Comma separate multi-selector, not as parameter

function show_div(id)
{
    $("#edit_tag"+id+ ",#save_li"+id).show();
    //               --^--
}

REF : Multiple-selector

Upvotes: 1

Related Questions