/    Sign up×
Community /Pin to ProfileBookmark

Getting value from span using javascript

Hello, I am trying to get the value(34.88) of a span in a CSS ussing javascript. I tried using getElementById with and without innerHtml but all that returns is null. Below is an example using the getElementById.

var s1 = document.getElementById(‘product”);

alert(s1);

I also tried the example with innerHtml and got nothing returned.

var s1 = document.getElementById(‘yfs_l10_palm’).innerHtml;

alert(s2);

Thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@WestWebJun 09.2010 — It must be the ordering of elements/scripts keeping the value null.

This works because the <span> element is loaded before the javascript:
[CODE]
<html>
<body>

<span id='s1'>34.88</span>

<script type="text/javascript">
var s1 = document.getElementById('s1').innerHTML;
alert(s1);
</script>

</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@xwol7822authorJun 09.2010 — It must be the ordering of elements/scripts keeping the value null.

This works because the <span> element is loaded before the javascript:
[CODE]
<html>
<body>

<span id='s1'>34.88</span>

<script type="text/javascript">
var s1 = document.getElementById('s1').innerHTML;
alert(s1);
</script>

</body>
</html>
[/CODE]
[/QUOTE]



Thanks for the info. How can I load the span before the javascript if the page

that has the span is a new page which is the result of a search page?. The new page has the span in it.

Thanks
Copy linkTweet thisAlerts:
@SparoHawkJun 09.2010 — Use:

[CODE]window.onload = function(){
// any code you want executed after the page loads
}[/CODE]
×

Success!

Help @xwol7822 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...