jimfog Posted November 26, 2011 Share Posted November 26, 2011 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 More sharing options...
Ingolme Posted November 26, 2011 Share Posted November 26, 2011 Did you make some sort of typing mistake here? this.this.(textMonths[month]);; Link to comment Share on other sites More sharing options...
dsonesuk Posted November 26, 2011 Share Posted November 26, 2011 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 More sharing options...
jimfog Posted November 27, 2011 Author Share Posted November 27, 2011 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 More sharing options...
thescientist Posted November 28, 2011 Share Posted November 28, 2011 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 More sharing options...
dsonesuk Posted November 28, 2011 Share Posted November 28, 2011 or$(this).prepend($('<p></p>').html(textMonths[month])); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.