How to retrieve the hover time with custom java script code | XM Community
Skip to main content
Solved

How to retrieve the hover time with custom java script code

  • July 27, 2022
  • 10 replies
  • 118 views

Forum|alt.badge.img+1

I have the below java script code to measure the time spent on hovering a flip-card (text question) in Qualtrics. I am trying to get the results of the time in seconds and unable to figure where the results are stored.

image.pngAny help would be appreciated.

Best answer by TomG

In Qualtrics $ refers to prototypejs. Use jQuery (

e.g., jQuery('.flip-card')
).

10 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • July 27, 2022

In Qualtrics $ refers to prototypejs. Use jQuery (

e.g., jQuery('.flip-card')
).


Forum|alt.badge.img+1
  • Author
  • July 27, 2022

Thank you TomG


Forum|alt.badge.img
  • Level 1 ●
  • May 28, 2023

In Qualtrics $ refers to prototypejs. Use jQuery (

e.g., jQuery('.flip-card')

).

 

 

Sorry but I am a newbee to JS and JQuery. I have unsure what is the solution here. Do you mean replace every $ with jQuery? Or do you mean use jQuery() covering all the functions?

 

Thank you very much


ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • May 29, 2023

 

Since Qualtrics framework also use the $ for its own scripting. So if two different frameworks are using the same shortcut, one of them might stop working. Just to resolve this issue jQuery has created one method called noConflict() . This method releases the hold on the $ shortcut identifier, so that other scripts can use it.

Example to use:

var jq = $.noConflict();

jq('.flip-card')

So wherever $ is mentioned in jQuery code you can replace it with jq. 

 


Forum|alt.badge.img
  • Level 1 ●
  • May 29, 2023

 

 

Since Qualtrics framework also use the $ for its own scripting. So if two different frameworks are using the same shortcut, one of them might stop working. Just to resolve this issue jQuery has created one method called noConflict() . This method releases the hold on the $ shortcut identifier, so that other scripts can use it.

Example to use:

var jq = $.noConflict();

jq('.flip-card')

So wherever $ is mentioned in jQuery code you can replace it with jq. 

 

Thank you very much for answering.

 

I am currently doing the similar thing, during to record the hover time as an embedded data (I posted the css, div and js). However, I found that the js never worked. It seems that function ‘hover’ is not working properly. 

 

Is it because I need some particular jQuery libraries to be loaded at somewhere? 

 

 


ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • May 29, 2023

Please confirm only hover code is not working or there are other jquery code which are also not working? Because if you are using simple layout then other code will also not work. Simple layout does not support JS.


ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • May 29, 2023

If you are not using simple layout. So do one thing, instead of saving it in embedded data, try to save it on open text box on same page and then hide that text box question through JS.


Forum|alt.badge.img
  • Level 1 ●
  • May 29, 2023

Please confirm only hover code is not working or there are other jquery code which are also not working? Because if you are using simple layout then other code will also not work. Simple layout does not support JS.

In fact, the code does not work since first line var jq = $.noClonflict();

However, if I add <script src="https://code.jquery.com/jquery-3.7.0.js"></script> to the top of the question block (html view), the first line will work pass but again stop working from the line with hover function.


ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • May 29, 2023

You should remove the embedded field and save hovertime under text box.


Forum|alt.badge.img
  • Level 1 ●
  • May 29, 2023

You should remove the embedded field and save hovertime under text box.

I have been trying for many times but function ‘hover’ still seems not working at all.

Is it because Qualtrics only allow in-built functions to trigger particular functions in js? For instance,  question click().