/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] innerHTML assignment not working

Recently, I’ve reworked a javascript tool that I’m working on to be a little more OO than it previously was. In doing this, some of my code is no longer working. I think it has to do with the function and/or members visibility, but I’m not sure.

var buildDiv = new function (obj){

var price = document.createElement(‘p’);
price.setAttribute(“id”, getNextPriceId());
price.style.margin = “20px 0px 0px 0px”;
price.style.padding = “0px 0px 0px 0px”;
price.style.fontSize = “12px”;
price.style.fontFamily = “Myraid Pro, Arial”;
price.style.fontWeight = “bold”;
price.innerHTML = obj.price;
priceDiv.appendChild(price);
}

The problem is that when I try to assign text into the innerHTML it doesn’t seem to take. While debugging, I can see that obj.price has information in it, but after stepping over the ‘price.innerHTML = obj.price’ line, it just assigned ‘undefined’ into the innerHTML.

buildDiv is a member of the class, ‘MyTool’. I know this is probably something easy that I’m just not seeing.

Thanks in advance!

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FangJan 26.2009 — Give the var price a different name.
Copy linkTweet thisAlerts:
@golfinusaauthorJan 26.2009 — I'm not sure why renaming price would effect anything. If you're thinking that it might be conflicting with obj.price, I don't think this is the case. obj.price isn't actually the name, the name is obj.listingPrice.

Thanks
Copy linkTweet thisAlerts:
@FangJan 26.2009 — For invalid attributes use [I]getAttribute[/I]price.innerHTML = obj.getAttribute('listingPrice');
Copy linkTweet thisAlerts:
@golfinusaauthorJan 27.2009 — Okay, thought I would post the actual resolution to the problem, but before I do, thank you, Fang, for helping me to resolve it.

It can be noted that part of the problem in me trying to get help was that I wasn't descriptive enough in my original post. So, for those of you reading, it's true what they say, give as much detail as possible.

'obj' being passed in was an object that I created. All of its variables are private, so accessing them directly isn't allowed. So, when I tried the following, it wouldn't work:

<i>
</i>price.innerHTML = obj.price;


I had created an accessor function, but had a brain fart where I not only forgot that it was a private object, but also that they were there to use. So, when Fang said to use:

<i>
</i>price.innerHTML = obj.getAttribute('listingPrice');


he could have been right in the context that he knew because the information I gave him was limited.

So, final result looks like this:

<i>
</i>price.innerHTML = obj.getPrice();
Copy linkTweet thisAlerts:
@golfinusaauthorJan 27.2009 — Complete
×

Success!

Help @golfinusa spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...