1

i have a java-script code which print the post to fb wall link and call a PostToWall Javascript function on click, in this function i am trying to read data under span by its id. But unfortunately its not returning the span data .Please help me to solve my problem.

First: this code prints on my html page after a certain JS function is called $('#content').html('<h1>You\'re done</h1><br/><a href="#" onclick="return postToWall();"> Share your score in FACEBOOK</a>\n

Second: Users click on the "Share your ...FB" then it calls this function:

function postToWall() { var msg = document.getElementById("timespent"); alert(msg); ------ } 

It is callin func but its not showing the data under under span id=timespent

where <span id="timespent" style="zoom: 80%" class="timeisplay">4732</span>

2 Answers 2

1

You have put the timespent span object in alert instead of its html. You need to using innerHTML to show the html with span

alert(msg.innerHTML); 
Sign up to request clarification or add additional context in comments.

6 Comments

yes now its fine. But in jquery there is no need to put like this innerHtml why in javascript? In jquery simply $("timespent").html();
jQuery has function html but javascript COM object does not have it. If you have DOM object you should try using native properties. It will give you performance benefits
thanks, but what do you mean by If you have DOM object you should try using native properties. ?
Reading this will help understand what DOM and jQuery are and how they differ. JQuery is wrapper over javascript but jQuery is usually slower then javascript
Reading this but what? I think you forget to attach link in your previous comment.-:)
|
0

Simple. Try in jQuery.

alert($('#timespent').text()); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.