0

Here is my code.. This is giving me a hard time though I know there is a simple answer

var myVAr = '<%=data.name%>';

$(myVAr).insertAfter("#thisDiv");
3
  • 1
    What is the problem? What happens and what do you expect to happen? What is data.name? Your code you posted seems to be correct given that data.name exists and has a value that is understandable by jQuery. Commented Sep 15, 2011 at 15:41
  • for some reason it just gives me the plain text and not the value or the var Commented Sep 15, 2011 at 15:46
  • If you response.write data.name straight onto the HTML page, what do you find? Commented Nov 16, 2011 at 21:01

2 Answers 2

1

You must call insertAfter on a jquery object. So you could do:

var myVAr = $('<input>',{name :'<%=data.name%>', type: "text"} );

myVAr.insertAfter("#thisDiv");

fiddle here http://jsfiddle.net/FhUF5/

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

Comments

0

Make sure the data.name does not have a ' inside it as it will break the javascript string.

And then make sure that the jquery code is executed after the page has loaded

var myVAr = '<%=data.name%>';
$(function(){
  $(myVAr).insertAfter("#thisDiv");
});

If the data.name does not represent valid html code, and you just want the data.name to be inserted as text after the #thisDiv then make a tag with jquery which holds the data.name

var myVAr = '<%=data.name%>';
$(function(){
  $('<span>',{text:myVAr}).insertAfter("#thisDiv");
});

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.