0

I am using this code to append some code to a div.

$(document).ready(function () {
$("div[style='padding-left: 6px;']").append("<table  style=\"width: 6px; display: inline-block;\" cellspacing=\"0\" cellpadding=\"0\" toolbarspacer=\"true\"><tbody><tr><td></td></tr></tbody></table><div  onclick=\"CallMethod()\"   class=\" \" style=\"font-family: Verdana; font-size: 8pt; vertical-align: top; display: inline-block;\"><table style=\"display: inline;\" cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td height=\"28\"><div onmouseout=\"this.style.background=\'transparent\', this.style.border=\'1px transparent Solid\'\" onmouseover=\"this.style.background=\'#DDEEF7\', this.style.border=\'1px #336699 Solid\'\" id=\"rptViewer_ctl05_ctl05_ctl00_Email\"><div \" id=\"rptViewer_ctl05_ctl05_ctl00_ctl00_Email\" style=\"border: 1px solid transparent; border-image: none; cursor: default; background-color: transparent;\"><table title=\"Email\"><tbody><tr><td><input name=\"rptViewer$ctl05$ctl05$ctl00$ctl00$ctl00_Email\" title=\"Email\" style=\"width: 20px; height: 20px;\" type=\"image\" alt=\"Email\" src=\"" + url + "Images/email.png\" \"></td></tr></tbody></table></div><div disabled=\"disabled\" class=\"aspNetDisabled\" id=\"rptViewer_ctl05_ctl05_ctl00_ctl01_Email\" style=\"border: 1px solid transparent; border-image: none; display: none;\"><table title=\"E-Mail\"><tbody><tr><td><input name=\"rptViewer$ctl05$ctl05$ctl00$ctl01$ctl00_Email\" title=\"E-Mail\" disabled=\"disabled\" style=\"width: 20px; height: 20px; cursor: default;\" type=\"image\" alt=\"E-Mail\"  src=\"" + url + "Images/email.png\"></td></tr></tbody></table></div></div></td></tr></tbody></table></div>");
});

This is working fine in IE. Find the screenshot. enter image description here

I am using the code to add the highlighted email button. Clicking on this button I am calling a onclick event .

Kindly let me know another way for achieving the same or let me know where I am wrong?

Shivan Bhatia
  • 38
  • 2
  • 10

1 Answers1

0

I ran this locally in Chrome and I get an error because url is not defined: if you define the url value does it work for you?

Alternatively you could try logging out $("div[style='padding-left: 6px;']") to see if returns anything?

I'd suggest using a class to select your div rather than the style attribute.

Added a CodePen example : http://codepen.io/anon/pen/VKadwB

Paul
  • 961
  • 1
  • 6
  • 20
  • yes url thing is working. I have not added that code. – Shivan Bhatia Sep 15 '16 at 10:16
  • I tried this $("div[style='padding-left: 6px;']").hide(); but this is also not working. It means in Chrome or Firefox it is not able to find the div – Shivan Bhatia Sep 15 '16 at 10:20
  • I suspect it's because you're trying to find the div by an attribute - is there class on the div you want to append to? That's more reliable – Paul Sep 15 '16 at 10:22
  • I cannot do that as this div is being created by SSRS report viewer and I am trying to add this to a asp control and it dont have a id or a class – Shivan Bhatia Sep 15 '16 at 10:26