4 Replies - 502 Views - Last Post: 01 August 2014 - 11:22 AM

#1 ssbodyrock  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 08-June 14

Using this key word to point to an area.

Posted 30 July 2014 - 01:18 PM

Trying to create a function that will identify what the user is hovering over. The first line of the function is where my question comes in. The document did not return any errors, but obviously does not work. But this is the line I have a bad feeling about. >> var areaIndex = this.srcElement.index;<<
The variable reindex has to be declared which equals to the value of the index property for the area element that was initiated by the mouseover event. This should be used for the reference.


function writeFrame() {

//declare areaIndex variable equal to index property property for the area element that initiated
//on mouseover event.. use this keyword to reference the area element 
    var areaIndex = this.srcElement.index;
    
//declare a var frameWin referencing the window containing the parts inline frame 
// var frameWin = getElementById("parts").documentWindow;
    var frameWin = document.getElementById("parts");
    var frameDoc = frameWin.contentwindow.document;
    
//set the innerHTML for the element id docTitle to the value
//of title array element whose index is =l to areaIndex 
frameDoc.getElementById("docTitle").innerHTML = title[areaIndex];    
    
//set the innerHTML for the element id docSummary with value of 
//summary array element whose index is equal to areaIndex
frameDoc.getElementById("docSummary").innerHTML = summary[areaIndex];    
    
}





Is This A Good Question/Topic? 0
  • +

Replies To: Using this key word to point to an area.

#2 ArtificialSoldier  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 399
  • View blog
  • Posts: 1,459
  • Joined: 15-January 14

Re: Using this key word to point to an area.

Posted 30 July 2014 - 01:38 PM

What you mean you have a bad feeling about that line? What does areaIndex get set to? Is it correct? What are this and this.srcElement set to, have you used console.log to inspect those?
Was This Post Helpful? 1
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3516
  • View blog
  • Posts: 12,003
  • Joined: 12-December 12

Re: Using this key word to point to an area.

Posted 30 July 2014 - 01:42 PM

Are there errors in your browser's console?

srcElement is an IE property, and you would typically use:
var eTarget = event.target || event.srcElement;

but this requires the event object, passed to an event-handler: this won't refer to the event object. Here's an example:
<script>
  function clickHandler(event) {
    var eType = event.type;
    /* the following is for compatibility */
    /* Moz populates the target property of the event object */
    /* IE populates the srcElement property */
    var eTarget = event.target || event.srcElement;

    alert( "Captured Event (type=" + eType + ", target=" + eTarget + ")" );
  }
</script>
<span onclick="clickHandler(event);">Click Here</span>

From this page.
Was This Post Helpful? 1
  • +
  • -

#4 ssbodyrock  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 08-June 14

Re: Using this key word to point to an area.

Posted 31 July 2014 - 07:27 PM

There are no errors but how would I use "this" to go along with the onmouse event? It would not be areaindex=event.this.index?
Was This Post Helpful? 0
  • +
  • -

#5 ArtificialSoldier  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 399
  • View blog
  • Posts: 1,459
  • Joined: 15-January 14

Re: Using this key word to point to an area.

Posted 01 August 2014 - 11:21 AM

this isn't a property on other objects, event.this doesn't make sense. But, see for yourself, print the event object to the browser's console and then look through it to see what's there:

console.log(event);
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1