Kar Inter
Kar Inter

Reputation: 303

How to select some elements as selector in jQuery?

I have some elements like TextBox, Select. I have a script to hide some elements. For this I use the code below, but it doesn't work:

$(document).on('change', '#TypeId', function (e) {
  var selected = $(this).val();
  if (selected == 1) {
    $($('#Issue').parent(), $('#ServiceRequestId').parent()).hide();
    console.log('test');
  }
});

It just hides the first selector. When I change the selector like below it works fine:

$( $('#ServiceRequestId').parent()).hide();

Upvotes: 1

Views: 46

Answers (1)

Pranav C Balan
Pranav C Balan

Reputation: 115202

The second argument is the context in jQuery which would help to filter element within that context.

I think you want to combine both objects, for that use add() method to combine two independent jQuery objects.

$('#Issue').parent().add($('#ServiceRequestId').parent()).hide();

Or provide both jQuery objects within an array.

$([$('#Issue').parent(), $('#ServiceRequestId').parent()]).hide()

Upvotes: 2

Related Questions