0

I am adding an image in a loop by iterating using struts tag. I've an image for which tooltip can vary depending on certain condtion.

I'm adding image in the following way inside a loop -

<logic:iterate> ....
<img src="../images/report_<bean:write name="vo" property="field(repType)" bundle="coreRes"/>.png" width="13" height="13" style="vertical-align: middle; cursor:pointer;" id = "repImg" onmouseover = "generateTooltip('<bean:jsParam name="vo" property="field(repType)" bundle="esmcoreRes"/>')" 

</logic:iterate>

based on the repType value i'll be adding different images. For instance if repType returns "1" i'll add an image as "A", if "2" image will be "B" . Now i need to add a tooltip which will display different values depending on the reportType.

below is the javascript code i tried -

function generateTooltip(repType){

var tooltip = '';

// logic to determine tooltip based on repType is written here

    //$('#repImg').prop('title', tooltip );
    $("#repImg").attr('title', tooltip );
    //$("#repImg").css('cursor','pointer').attr('title', tooltip );
}

I've tried several approach in Javascript method mentioned above. But the tooltip is getting displayed only for the 1st image. For rest of the images tooltip isn't getting displayed.

Can anyone help me on this.

1
  • 2
    why the java tag? Commented Jun 7, 2018 at 11:09

1 Answer 1

1

You have to use .each() function, or just change ID to class. jQuery just select 1 element if your selector is a #ID

try :

$(".repImg").attr('title', tooltip );

and

<logic:iterate> ....
<img class="repImg" src="...

More info: https://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-item-using-class-or-id/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.