HighDots Forums  

cannot insert html into DIV

jQuery jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.


Discuss cannot insert html into DIV in the jQuery forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
shaf
 
Posts: n/a

Default cannot insert html into DIV - 11-04-2009 , 06:16 PM






Hi Guys,

I have several .class DIVs I want to manipulate. I have retrieved them
using the following code:

var canvasClasses = new Array();
$(".canvas").each(function() {
canvasClasses.push()
});

I am now trying to insert some HTML into the DIVs but its not working:

canvasClasses[0].innerHTML = "htmlhere";

Any ideas on why its not working ?

Reply With Quote
  #2  
Old   
RayJames
 
Posts: n/a

Default Re: cannot insert html into DIV - 11-04-2009 , 06:20 PM






Hey buddy, I think you need to use .html and not innerHTML.

http://docs.jquery.com/Attributes/html

look at the html(val) example.

Hope this works for you.

Ray James

On Nov 4, 4:16*pm, shaf <shaolinfin... (AT) gmail (DOT) com> wrote:
Quote:
Hi Guys,

I have several .class DIVs I want to manipulate. I have retrieved them
using the following code:

* * * * var canvasClasses = new Array();
* * * * $(".canvas").each(function() {
* * * * * * * * canvasClasses.push()
* * * * });

I am now trying to insert some HTML into the DIVs but its not working:

canvasClasses[0].innerHTML = "htmlhere";

Any ideas on why its not working ?

Reply With Quote
  #3  
Old   
Andrew Tan
 
Posts: n/a

Default Re: [jQuery] cannot insert html into DIV - 11-04-2009 , 06:28 PM



You have to supply the canvas object as a parameter to the push function to
add it to the array.

canvasClasses.push($(this));

On Thu, Nov 5, 2009 at 10:16 AM, shaf <shaolinfinest (AT) gmail (DOT) com> wrote:

Quote:
Hi Guys,

I have several .class DIVs I want to manipulate. I have retrieved them
using the following code:

var canvasClasses = new Array();
$(".canvas").each(function() {
canvasClasses.push()
});

I am now trying to insert some HTML into the DIVs but its not working:

canvasClasses[0].innerHTML = "htmlhere";

Any ideas on why its not working ?

Reply With Quote
  #4  
Old   
Andrew Tan
 
Posts: n/a

Default Re: cannot insert html into DIV - 11-04-2009 , 06:29 PM



You have to supply the canvas object as a parameter to the push
function to add it to the array.

canvasClasses.push($(this));

Reply With Quote
  #5  
Old   
shaf
 
Posts: n/a

Default Re: cannot insert html into DIV - 11-04-2009 , 06:35 PM



That doesnt work either.

On Nov 4, 11:28*pm, Andrew Tan <afh... (AT) gmail (DOT) com> wrote:
Quote:
You have to supply the canvas object as a parameter to the push function to
add it to the array.

canvasClasses.push($(this));

On Thu, Nov 5, 2009 at 10:16 AM, shaf <shaolinfin... (AT) gmail (DOT) com> wrote:
Hi Guys,

I have several .class DIVs I want to manipulate. I have retrieved them
using the following code:

* * * *var canvasClasses = new Array();
* * * *$(".canvas").each(function() {
* * * * * * * *canvasClasses.push()
* * * *});

I am now trying to insert some HTML into the DIVs but its not working:

canvasClasses[0].innerHTML = "htmlhere";

Any ideas on why its not working ?

Reply With Quote
  #6  
Old   
mkmanning
 
Posts: n/a

Default Re: cannot insert html into DIV - 11-04-2009 , 07:04 PM



If you used Andrew's example, then you added a jQuery object to the
canvasClasses array. Calling innerHTML on a jQuery object won't work.
Try canvasClasses[0].html('htmlhere')

On Nov 4, 3:35*pm, shaf <shaolinfin... (AT) gmail (DOT) com> wrote:
Quote:
That doesnt work either.

On Nov 4, 11:28*pm, Andrew Tan <afh... (AT) gmail (DOT) com> wrote:



You have to supply the canvas object as a parameter to the push function to
add it to the array.

canvasClasses.push($(this));

On Thu, Nov 5, 2009 at 10:16 AM, shaf <shaolinfin... (AT) gmail (DOT) com> wrote:
Hi Guys,

I have several .class DIVs I want to manipulate. I have retrieved them
using the following code:

* * * *var canvasClasses = new Array();
* * * *$(".canvas").each(function() {
* * * * * * * *canvasClasses.push()
* * * *});

I am now trying to insert some HTML into the DIVs but its not working:

canvasClasses[0].innerHTML = "htmlhere";

Any ideas on why its not working ?

Reply With Quote
  #7  
Old   
shaf
 
Posts: n/a

Default Re: cannot insert html into DIV - 11-04-2009 , 07:58 PM



Thanks that worked.

Ok, I am now trying to add several google maps using the same method
to no avail. Code below:

$(document).ready(function(){
/*Create Map/Address/.map_canvas class Arrays*/
var map = new Array();
var mapCanvasClasses = new Array();

/*Load Default view on map*/
geocoder = new google.maps.Geocoder();
var myLatlng = new google.maps.LatLng(51.50, -0.07);
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

/*Get all map_canvas class instances*/
$(".map_canvas").each(function() {
mapCanvasClasses.push($(this));
});

/*suspect problem here*/
map[0] = new google.maps.Map(mapCanvasClasses[0], myOptions);
});

I suspect the the problem is with the second last line, or more
accurately the "mapCanvasClasses[0]" bit. Whenever I replace that with
a getElementById("map_canvas") it will work. But since I am using
multiple DIV classes I cannot use the getElementById() function. Any
ideas on how I can fix this ?



On Nov 5, 12:04*am, mkmanning <michaell... (AT) gmail (DOT) com> wrote:
Quote:
If you used Andrew's example, then you added a jQuery object to the
canvasClasses array. Calling innerHTML on a jQuery object won't work.
Try canvasClasses[0].html('htmlhere')

On Nov 4, 3:35*pm, shaf <shaolinfin... (AT) gmail (DOT) com> wrote:

That doesnt work either.

On Nov 4, 11:28*pm, Andrew Tan <afh... (AT) gmail (DOT) com> wrote:

You have to supply the canvas object as a parameter to the push function to
add it to the array.

canvasClasses.push($(this));

On Thu, Nov 5, 2009 at 10:16 AM, shaf <shaolinfin... (AT) gmail (DOT) com> wrote:
Hi Guys,

I have several .class DIVs I want to manipulate. I have retrieved them
using the following code:

* * * *var canvasClasses = new Array();
* * * *$(".canvas").each(function() {
* * * * * * * *canvasClasses.push()
* * * *});

I am now trying to insert some HTML into the DIVs but its not working:

canvasClasses[0].innerHTML = "htmlhere";

Any ideas on why its not working ?

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.