0

jQuery

$("select[id^='_taskAssignedTo_']").each(function(id) {
    if ($(this).val() == "1") {
        $(this).next().find("select[id^='_taskStatus_']").prop("disabled", false);
    }
});

HTML

<td>
    <select id="_taskAssignedTo_1"> <!-- options --> </select>
<td>
<td>
    <select id="_taskStatus_1"> <!-- options --> </select>
<td>

I am looping through and finding the first select because it has the value I need to search for and I want to enable the select next to it called, _taskStatus_1. There are many, so it is important I use the "start with" syntax.

The code above does not work. I am not sure if I need to use next, find, something else, or a combination?

8
  • 1
    it is better to provide jsfiddle link or something like that
    – Lab
    Feb 20, 2014 at 22:30
  • 2
    @Neo the problem is perfectly clear in the provided code.
    – Jason P
    Feb 20, 2014 at 22:30
  • 2
    Ideally, when you want to add a CSS hook to more than one element, use a class instead of an id. If you then want to also assign unique identifiers to elements with that class use data-id or #prefix-{someid}, as required. Feb 20, 2014 at 22:32
  • 1
    @JasonP yes it is but it makes "testing of code" easier
    – Lab
    Feb 20, 2014 at 22:33
  • Maybe I'm misunderstanding something, but why can't you just use: $(#_taskStatus_1)? Feb 20, 2014 at 22:36

2 Answers 2

3

Just do:

$(this).closest("td").next("td").find("select[id^='_taskStatus_']");

You have to first travel back to your td (closest) - then to the next td (next) - then find the element you're looking for.

0
1

Try:

$(this).parent().next().find("select[id^='_taskStatus_']").prop("disabled", false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.