Jump to content

Targeting A Month Object


jimfog

Recommended Posts

Using getMonth i have inserted the month inside a div(.calendar). I want, using jQuery to wrap this in a p tag, since now, it is just a text node. Here is the code i used(and did not work):

$('.calendar').contents().filter(function() {  return this.this.(textMonths[month]);;}).wrap('<p class="month"/>');

What is wrong in the above "picture"? The code that outputs the month is the following:

$('.calendar:eq(1)').prepend(function(){var f = new Date();var d = new Date(f.getFullYear(), f.getMonth(), 1);var month = (d.getMonth() + 1) % 12;textMonths = [----monthsgohere"];$(this).prepend(textMonths[month]);});

The above code was created with the contribution of other forum members here http://w3schools.invisionzone.com/index.php?showtopic=40801&hl=&fromsearch=1

Link to comment
Share on other sites

Why not just output within Paragraph tags

$('.calendar:eq(1)').prepend(function(){var f = new Date();var d = new Date(f.getFullYear(), f.getMonth(), 1);var month = (d.getMonth() + 1) % 12;textMonths = [----months go here"];$(this).prepend('<p>'+textMonths[month]+'</p>');});

Or place empty p tag with class, and then add the month using html()

$('.calendar:eq(1)').prepend(function(){var f = new Date();var d = new Date(f.getFullYear(), f.getMonth(), 1);var month = (d.getMonth() + 1) % 12;textMonths = [----months go here"];$(this).children('p.month').html(textMonths[month]);});

Link to comment
Share on other sites

Why not just output within Paragraph tags
$('.calendar:eq(1)').prepend(function(){var f = new Date();var d = new Date(f.getFullYear(), f.getMonth(), 1);var month = (d.getMonth() + 1) % 12;textMonths = [----months go here"];$(this).prepend('<p>'+textMonths[month]+'</p>');});

Or place empty p tag with class, and then add the month using html()

$('.calendar:eq(1)').prepend(function(){var f = new Date();var d = new Date(f.getFullYear(), f.getMonth(), 1);var month = (d.getMonth() + 1) % 12;textMonths = [----months go here"];$(this).children('p.month').html(textMonths[month]);});

At last, a solution was find, many thanks.I am not experienced with jQyery and in general with javascript...still learming.
Link to comment
Share on other sites

you could also create the p element on the fly

var p = $('<p></p>');p.html(textMonths[month]);//append or insert into element here

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...