0

i'm using this

jQuery('#mydiv').datetimepicker({ ... });

How can i use this function for more than just one ID?

Thought something like this should do the job but it doesn't :(

jQuery('#mydiv','#anotherdiv).datetimepicker({ ... });
jQuery('#mydiv|#anotherdiv).datetimepicker({ ... });

Any ideas? Thanks!

2
  • give your divs a common class, then $('.myclass').datetimepicker... Commented May 5, 2017 at 21:46
  • JQuery ('#result, #mydiv') jQuery nesnesi bölme sözdizimi ... Commented May 6, 2017 at 1:14

3 Answers 3

2

Use a single argument with the IDs separated with commas, not separate arguments.

jQuery('#mydiv,#anotherdiv').datetimepicker({ ... });
Sign up to request clarification or add additional context in comments.

Comments

0

Give the respective Divs a class name, then reference them like this:

jQuery('.className').datetimepicker({ ... });

Comments

0

A common class would be the best solution, as @simon suggested.

If you absolutely need to use IDs (eg you can only modify the JS, and not the DOM), you can loop through an array of IDs:

$.each(['mydiv', 'anotherdiv'], function (index, value)
{
    $.('#' + value).datepicker({ ... });
}

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.