code for highlighting rows | XM Community
Skip to main content
Solved

code for highlighting rows

  • October 14, 2021
  • 8 replies
  • 102 views

I am building a survey where we provide a matrix and we only want the respondent to fill out specific rows of the matrix, not all rows. Does anyone know a code where I can highlight specific rows to have a different background color to identify which rows we want the respondent to fill out? I do not want the code to make alternating shading of rows. Thanks!

Best answer by TomG

You could add a span with a class of 'hilite' to all the statement rows you want to highlight, like:
Statement text
Then use this JS:
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId+" .hilite").each(function() {
jQuery(this).closest("tr").css("background-color","yellow");
});
});

8 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • October 14, 2021

You could add a span with a class of 'hilite' to all the statement rows you want to highlight, like:
Statement text
Then use this JS:
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId+" .hilite").each(function() {
jQuery(this).closest("tr").css("background-color","yellow");
});
});


  • Author
  • October 14, 2021

TomG thanks for your response. do I add the span in the javascript? or where do I put it? also, where do I identify which row to highlight in the javascript?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • October 14, 2021

https://community.qualtrics.com/XMcommunity/discussion/comment/41157#Comment_41157You put the span(s) in the statement text of your matrix rows. The JS will find the rows for you.


  • Author
  • October 14, 2021

TomG this works great, thank you. the only problem is now when i preview the survey, it has "statement text" written out after my statement text. is there a way to get rid of this? thanks.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • October 14, 2021

https://community.qualtrics.com/XMcommunity/discussion/comment/41159#Comment_41159"statement text" was only an example. It was meant to be whatever your row label text is. Since you've already done it, you can just delete "statement text" and leave the span empty. It will still work.


  • Author
  • October 14, 2021

TomG I solved this problem, thank you so much for your help!


  • Author
  • October 14, 2021

TomG Hi Tom, sorry to bother you again.
this worked for all questions except two. for some reason, in two of my questions, the highlighting is applying to the entire matrix, even though i only entered the span into some questions. any idea why this is happening? Thanks!


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • October 14, 2021

https://community.qualtrics.com/XMcommunity/discussion/comment/41163#Comment_41163Hard to say without seeing it. It may be a missing a closing tag (e.g.,

) or a typo in the html.