Pierre Pierre - 4 months ago 7
Ajax Question

Get the text outside a DIV element with jQuery

I'm trying to access a page and get the value from this page.

First I don't have access to this page so I can't do any modification on the code, that's the problem because it doesn't look coded properly.

Please find an example (index.html) of the page (source)

I access this page with an ajax get method.

<div id="box" style="background-color:#000000; margin:0px;">
<b>
<big>
<span style="color:#00BB77;">Tue, 02-08-2016</span>
</big>
</b>
</div>
MobApp iOS.A in C04
<br>
09:00 am-11:00 am
<br>
<b>
<big></big>
</b>
<br>
MobApp Andr .A in C12
<br>
01:30 pm-03:30 pm
<br>
<b>
<big></big>
</b>
<br>
<div id="box" style="background-color:#000000; margin:0px;">
<b>
<big>
<span style="color:#00BB77;">Wed, 03-08-2016</span>
</big>
</b>
</div>
Adv. Studio 1.A in C11
<br>
01:30 pm-03:30 pm
<br>
<b>
<big></big>
</b>
<br>
<div id="box" style="background-color:#000000; margin:0px;">
.....etc....


I already wrote a sample of a code to get the value inside the span (the date) with:

$.ajax({
url: 'http://www.thewebsite.com/index.html',
type: 'GET',
success: function(res) {
var data = $.parseHTML(res);
$(data).find('#box').each(function() {
alert($(this).find('span').html());
});
}
});


And it works I get :
Tue, 02-08-2016
Wed, 03-08-2016 etc...

I would like now to get what's after the
</div>
and the
<br>
(The subject) and the (time)

As you can see sometimes it can be only one subject per day or more.

I know it would have been much easier if everything would have been inside proper div element but they coded their website long time ago and they won't change that..

Answer

You can do with javascript child node with below way:

 var children= (document.getElementById("box")).childNodes;
 var i=-1,length=children.length;
 while(++i <  length){
  //chidrent text node will also come
 console.log(children[i]);

 }