0

I am trying to create image tag string in javascript. This image tag in part of table row string. At the end I will append this table row string to mvc webgrid using jquery.

I have a javascript function which returns this new row

function getNewRow(email, friendlyName) {
 var imgSrc = "/Content/Images/User.png";

 // Create the new row html
 var newRow = '<tr class=\"' + rowClass + '\">' +    
'<td><text><img src\"' + imgSrc + '\"></text></td>' +
 '<td>' + email + '</td>' +    
 '<td>' + friendlyName + '</td>' +     
 '</tr>'
 return newRow;
  }

I will append returned string to webgrid object.

// Append the new Row
 $('#group').append(newRow);

But the image tag is not showing proper image. The forward slash is removed after appending. Used encodeURIComponent function but no use. How to make it to show the image properly.

5

2 Answers 2

1

You have <img src\"' + imgSrc + '\"></text></td> when it should be <img src=\"' + imgSrc + '\"></text></td>. Notice the missing =.

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

Comments

1

It seems that you have a typo in the second line of newRow declaration, you are missing the = sign after src attribute

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.