Jquery Multiple Id Selectors

jQuery Multiple ID selectors

Try this:

$("#upload_link,#upload_link2,#upload_link3").each(function(){
$(this).upload({
//whateveryouwant
});
});

jquery selector on multiple id

$("#prezzo,#quantita,#prodotto").each(function()
{
if ($(this).val() !="" )
{}
else
{}
});

Is there a more efficient way to combine multiple id selectors each with a child selector in jQuery?

Use .children()

$("#div1, #div2, #div3").children("input[type=checkbox]").click(function() {
// do stuff
});

jQuery - event target multiple id selectors?

Just use the id selectors to get each value and ignore the event object. The event object knows nothing about the other element. It only references the element the specific change occurred on

const value1 = $('#test-input').val(), 
value2 = $('#input').val();

jquery multiple id selectors through php echo

Use class instead id ,change in html

<a class="clinks msgr" style="text-decoration: none; font-weight:bold;" id="msgr_<?php echo $d['qid'];?>" href="javascript:void(0)">message</a>
<div id="chatbox_<?php echo $d['qid'];?>" > </div>

And in JS

$(".msgr").click(function(){
var id = $(this).attr("id").split("_")[1];
$("#chatbox_"+id).fadeIn();
});

Added an example

$(".msgr").click(function(){    var id = $(this).attr("id").split("_")[1];    $("#chatbox_"+id).fadeToggle();    console.log("chatbox_"+id);});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div><a class="clinks msgr" style="text-decoration: none; font-weight:bold;" id="msgr_1" href="javascript:void(0)">message</a><div id="chatbox_1" >test1</div></div><div><a class="clinks msgr" style="text-decoration: none; font-weight:bold;" id="msgr_2" href="javascript:void(0)">message</a><div id="chatbox_2" >test2</div></div><div><a class="clinks msgr" style="text-decoration: none; font-weight:bold;" id="msgr_3" href="javascript:void(0)">message</a><div id="chatbox_3">test3</div></div>

Handling multiple IDs in jQuery

Yes, #id selectors combined with a multiple selector (comma) is perfectly valid in both jQuery and CSS.

However, for your example, since <script> comes before the elements, you need a document.ready handler, so it waits until the elements are in the DOM to go looking for them, like this:

<script>
$(function() {
$("#segement1,#segement2,#segement3").hide()
});
</script>

<div id="segement1"></div>
<div id="segement2"></div>
<div id="segement3"></div>

Multiple ID jQuery Selector returns different than when a single ID selector

Because with this selector :

#racksTab,#condenserTab,#glycolTab .dropdown-menu li a

You are targeting three elements:

  1. Element with Id racksTab

  2. Element with Id condenserTab

  3. a element inside li child of .dropdown-menu child of Id element glycolTab

I guess you want all elements like the third one, so your selector must be:

#racksTab .dropdown-menu li a, #condenserTab .dropdown-menu li a, #glycolTab .dropdown-menu li a



Note: Maybe you don't need those selectors at all, I think you can improve your code with a more suitable selector as @j08691 points on the comments, but all will be based on the real markup, if you add it we can help U improve the code.

jQuery selector: Select multiple ID and get their values

Additionally to what VisioN said. I would like to encourage you to use classes for this purpose:

<div class="item" id="item1"></div>
<div class="item" id="item2"></div>
<div class="item" id="item3"></div>
<div class="item" id="item4"></div>
<div class="item" id="item5"></div>

And

$(".item").mouseout(...)

JQUERY Selector not working on multiple ids with same name

From the jQuery API Documentation:

id selector

Description: Selects a single element with the given id attribute.

If you wish to select multiple elements, you could give them all the same class="test" and then use:

$(".test").click(function(){
$("#div1").load("test.php?" + $(this).attr("albid"));
});

Note the use of $(this) inside the function.

Jquery ID selector doesnt work when multiple IDs are given

DEMO

You cannot have multiple id's for a element.

because the browser will only render the first one

$("#inp").val($("#index").length); //sets value 1
^ //add $ here

Read

Can a HTML element have multiple unique ID attributes?

id attribute



Related Topics



Leave a reply



Submit