saturation
asked on
Get innerText next to img tag
The following Javascript will do an alert of all the elements in the object, but I need it to specifically do an alert box with the phone number inside the code below ("222 333 4444"). There is always an img tag using the icon "SmallPhone.gif" to the left of the number, and I need to just get the innerHTML in between that tag and the next one and do the alert box. How can I do this?
<html>
<script>
window.attachEvent("onload",getData);
function getData() {
var myObject = document.getElementsByTagName("img")[0].nextSibling;
var x = [];
sVal = document.getElementById("_Dataoppo_primarypersonid").nextSibling;
for (var item in myObject) {
x.push(item + ": " + myObject[item]);
}
alert(x.join("\n"));
}
</script>
<body >
<SPAN ID=_Dataoppo_primarypersonid class=VIEWBOX >
<IMG SRC="/CRM61/img/Icons/test.gif" HSPACE=0 BORDER=0 ALIGN=TOP HEIGHT=16>
<A HREF="/CRM61/eware.dll/Do?SID=10739501843508&Act=220&Mode=1&CLk=T&Key0=2&Key2=13&Key7=14&Key27=10158&Key50=19">ssdf sdf</A>
<IMG SRC="/CRM61/img/Icons/SmallPhone.gif" HSPACE=0 BORDER=0 ALIGN=TOP HEIGHT=16>
222 333 4444
<input type=hidden name=_HIDDENoppo_primarypersonid value="13">
<input type="hidden" name="_HIDDENSearchFieldoppo_primarypersonid" id="_HIDDENSearchFieldoppo_primarypersonid" value="oppo_primarypersonid">
</SPAN>
</body>
</html>
As it stands the telephone number is floating, its not contained in any elements apart from the
<SPAN ID=_Dataoppo_primaryperson id class=VIEWBOX >
So i would create its own container
Regards,
Dan
<SPAN ID=_Dataoppo_primaryperson
So i would create its own container
Regards,
Dan
ASKER
Unfortunately, I don't have control over that portion of the page--I have to do with what is already there and figure out a way to get it from DHTML/Javascript in between <script> tags.
ASKER
I basically need to get the text in between the "SmallPhone.gif" img tag and the next tag which is the "_HIDDENSearchFieldoppo_pr imaryperso nid" but I'm not sure how to do this...It will always be between these two tags...
ASKER
I meant that I basically need to get the text in between the "SmallPhone.gif" img tag and the next tag which is the "_HIDDENoppo_primaryperson id" but I'm not sure how to do this...It will always be between these two tags...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<span id="tel"></span>
Then
var tel = document.getElementById('t
alert(tel.innerHtml);
Try that