Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have html like this below.
can anybody help, i am not getting any idea how to?
i need to get data below data from html with javascript.
1:45 PM ET, Wednesday, April 9, 2014
Busch Stadium, St. Louis,

HTML
<div class="sdi-quickhits">
      When: 1:45 PM ET, Wednesday, April 9, 2014<br/>Where: Busch Stadium, St. Louis, Missouri<br/>Temperature:
	60°
		<br/>Umpires: 
	Home -
			Dale Scott, 1B -
			Dan Iassogna, 2B -
			CB Bucknor, 3B -
			Hal Gibson III<br/>Attendance: 
		41137<br/></div>
Posted
Comments
Sergey Alexandrovich Kryukov 10-Apr-14 16:19pm    
Which HTML? The same page using your script, or from some external HTML file?
—SA

Please see my comment to the question. The thing is: if your HTML is the same where your script is used, it is parsed immediately, so you only manipulate DOM tree with Javascript.
Based on that, the answer 33 shows interesting technique which you can use to parse any HTML string: http://stackoverflow.com/questions/10585029/parse-a-html-string-with-js[^].

Also, jQuery already has an explicit HTML parser: http://api.jquery.com/jquery.parsehtml[^].

Alternatively, you can find some other available HTML parser: http://bit.ly/1hmkFs2[^].

For example: https://www.npmjs.org/package/htmlparser[^].

Besides, if you are sure that the HTML is written as well-formed XML document, you can parse it as XML: http://www.w3schools.com/xml/xml_parser.asp[^].

—SA
 
Share this answer
 
Try this. You have to change the code little bit to remove When:/Where:/br in the final text. But now you know the idea :)

JavaScript
function search() {
        var searchValue1 = "When: ";
        var searchValue2 = "Where: ";
        var searchValue3 = "Temperature: ";

        var elements = document.querySelectorAll('.sdi-quickhits');
        var index1 = elements[0].innerHTML.indexOf(searchValue1);
        var index2 = elements[0].innerHTML.indexOf(searchValue2);
        var index3 = elements[0].innerHTML.indexOf(searchValue3);

        if (index1 > -1 && index2 > -1 && index3 > -1) {
            var res1 = elements[0].innerHTML.substring(index1, index2);
            var res2 = elements[0].innerHTML.substring(index2, index3);
            alert(res1);
            alert(res2);
        }
    }
 
Share this answer
 
Comments
venkatpvc 10-Apr-14 16:51pm    
thank you sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900