Reputation: 442
I'm running into a problem with my code. I want to edit an element's href. I need it to send open up your email when clicked with a pre-made subject and body. I'm getting the error "Unexpected token ILLEGAL" though and I'm completely not sure why.
I was hoping someone could help me with this problem.
I need to edit this attribute in javascript, so putting it in the element to start with will not work!
There is a jsfiddle here.
Here is my:
HTML:
<a id = 'emailoff' href = "" target = "_blank">
<div id= "btn1">
<h2 id = "enter">Send Email</h2>
</div>
</a>
JAVASCRIPT:
$('#btn1').click(function(){
$("#emailoff").attr("href", "mailto: [email protected]
?subject=Your thinoptics glasses
body=To get your new thinoptics glasses simply click this link and pick the case and color you like best. You'll get free shipping on your order
WWw.Thinoptics.Com/[email protected]
Enjoy")
});
UPDATE:
The error is within: "mailto: [email protected]..."
Upvotes: 0
Views: 259
Reputation: 4110
You can't have line breaks inside the javascript string, that results in an unterminated literal and thus in the error you are getting. For readability, use:
"mailto: [email protected]" +
"?subject=Your thinoptics glasses " +
"body=To get your new thinoptics glasses"
or similar.
EDIT: If you need a line break, use \n
inside the string.
Upvotes: 8