[SOLVED] jQuery Image Object Behavior | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

[SOLVED] jQuery Image Object Behavior

I have a project I'm working on, and I need to be able to create html using strings; it's how I'm creating a single page tab layout in this project: https://code.sololearn.com/Wh117ebi576o What I noticed when trying to create a new image was that a new image object has a strange behavior. I can use jQuery to add the image to the DOM simply by selecting an element and passing the image object into the html() function. That works, but what doesn't work is if I try to add the image element object to a string: html = "<div id='map'>" + image + "</div>"; element.html(html); This doesn't work. Why doesn't this work? I have an example of it it the javascript of this code: https://code.sololearn.com/Wk9uVG9MmaD0

24th Nov 2018, 5:43 PM
Zeke Williams
Zeke Williams - avatar
4 ответов
+ 2
That's what I'm thinking too. I can only use the append methods for existing html in the DOM. Maybe I need to rethink the whole structure of my single-page tab system. I guess I could create the html I want to put the image into first, then append the image. The overall goal was to preload the image so it wouldn't have to load every time a user tabbed to other content. Still thinking on it. Thanks for the answer Taste
24th Nov 2018, 6:45 PM
Zeke Williams
Zeke Williams - avatar
24th Nov 2018, 6:48 PM
Taste
Taste - avatar
+ 2
That's interesting. I had no idea you could do that. Thank you Taste
24th Nov 2018, 10:05 PM
Zeke Williams
Zeke Williams - avatar
+ 1
I think its because its an object appended to a string, the html() method surely know how to handle an object, but not a simple string concatenation. Maybe use append() or appendTo()
24th Nov 2018, 6:10 PM
Taste
Taste - avatar