Skip to main content
deleted 23 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

call Call html() on two jqueryjQuery selector objects

In my webpage I have two places where I need my JavaScript to write dates. How to do it in one go?

Selectors:

var $today = $('#today');
var $selected = $('#selected');

My selectors are listed above.

If I were to do this alternatively the easy way, I'd do:

$('#today, #selected').html(date);

But I kind of need to reuse my #selected jqueryjQuery object throughout my code.

The only solution I came up with so far is...

$([$today, $selected]).each(function(idx, obj){obj.html(date);});

So isIs there a better way?

call html() on two jquery selector objects

In my webpage I have two places where I need my JavaScript to write dates. How to do it in one go?

var $today = $('#today');
var $selected = $('#selected');

My selectors are listed above.

If I were to do this alternatively the easy way, I'd do:

$('#today, #selected').html(date);

But I kind of need to reuse my #selected jquery object throughout my code.

The only solution I came up with so far is...

$([$today, $selected]).each(function(idx, obj){obj.html(date);});

So is there a better way?

Call html() on two jQuery selector objects

In my webpage I have two places where I need my JavaScript to write dates. How to do it in one go?

Selectors:

var $today = $('#today');
var $selected = $('#selected');

If I were to do this alternatively the easy way, I'd do:

$('#today, #selected').html(date);

But I kind of need to reuse my #selected jQuery object throughout my code.

The only solution I came up with so far is...

$([$today, $selected]).each(function(idx, obj){obj.html(date);});

Is there a better way?

Source Link
deostroll
  • 175
  • 1
  • 6

call html() on two jquery selector objects

In my webpage I have two places where I need my JavaScript to write dates. How to do it in one go?

var $today = $('#today');
var $selected = $('#selected');

My selectors are listed above.

If I were to do this alternatively the easy way, I'd do:

$('#today, #selected').html(date);

But I kind of need to reuse my #selected jquery object throughout my code.

The only solution I came up with so far is...

$([$today, $selected]).each(function(idx, obj){obj.html(date);});

So is there a better way?