2

i have used ajax to get set of values from server and displayed using span.span display so many contents,but from that i want to select only one content from the list.

var z=document.getElementById("spanOutput").innerHTML=xmlhttp.responseText;

response from server like:

content 1

content 2

content 3

So I want to select content 2 from span element and need to displayed on the browser. How to achieve this?

4
  • 1
    Please make an example on a service such as jsbin.com. Your question is unclear. Commented Sep 3, 2013 at 4:02
  • You response is plain text or it has some sort of struture? Commented Sep 3, 2013 at 4:08
  • Can you make this a bit more clear? Do you have in the same span "content 1 content 2 content 3" all together? What does separates the content 1 with the content 2? Just a break line? Is there any chance you are going to have a break line in any of the contents? We will require more info... Commented Sep 3, 2013 at 4:43
  • Content 1,content 2 and so on are simply text or some kind of html element ? Commented Sep 3, 2013 at 4:53

2 Answers 2

1

Define a Array to save these span contents.

var arr=[];
for(var i=0; i<document.getElementById("spanOutput").getElementsByTagName("span").length;i++)
{
arr.push(document.getElementById("spanOutput").getElementsByTagName("span")[i]);
}

comtent 2 will be arr[ 1 ]

Sign up to request clarification or add additional context in comments.

Comments

0

Use value property:

var z = document.getElementById("spanOutput").value;
document.getElementById("spanOutput").value = xmlhttp.responseText;

1 Comment

i just want to select only few text.not the whole span content

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.