ebolt007 Posted March 15, 2012 Share Posted March 15, 2012 Is there a way to .prepend(""); multiple lines of code? Like if I have something like <div class="comment-main2"> <div class="commentname"> <a href="/profile/index.php?id=1" title="Eric">Eric</a> </div> </div> what would be the best way to use $("ul#wall").prepend("") would I have to go $("ul#wall").prepend("<div class=\"comment-main2\"><div class=\"commentname\"><a href=\"/profile/index.php?id=1\" title=\"Eric\">Eric</a></div>"); or how could I go $("ul#wall").prepend(" <div class=\"comment-main2\"> <div class=\"commentname\"> <a href=\"/profile/index.php?id=1\" title=\"Eric\">Eric</a> </div> "); So it's cleaner and easier to read then all of it in one loooooong line? Quote Link to comment https://forums.phpfreaks.com/topic/259018-prepend-multiple-lines/ Share on other sites More sharing options...
AyKay47 Posted March 15, 2012 Share Posted March 15, 2012 Either one is fine, as long as you escape the quotes. Easiest way to check these would be to test them. Quote Link to comment https://forums.phpfreaks.com/topic/259018-prepend-multiple-lines/#findComment-1327899 Share on other sites More sharing options...
ebolt007 Posted March 15, 2012 Author Share Posted March 15, 2012 The second one doesn't work tho for me unless I put it all in a straight line, which is a pain to work with then. Quote Link to comment https://forums.phpfreaks.com/topic/259018-prepend-multiple-lines/#findComment-1327900 Share on other sites More sharing options...
AyKay47 Posted March 15, 2012 Share Posted March 15, 2012 I honestly forget how JS handles carriage returns,tabs and such inside of a method. I always use a single line of code when doing something like this. Quote Link to comment https://forums.phpfreaks.com/topic/259018-prepend-multiple-lines/#findComment-1327902 Share on other sites More sharing options...
kicken Posted March 15, 2012 Share Posted March 15, 2012 JS doesn't allow a string to span across lines like that. I believe you can place a \ at the end of each line and it will work. Otherwise you concatenate the strings together. $("ul#wall").prepend("\ <div class=\"comment-main2\">\ <div class=\"commentname\">\ <a href=\"/profile/index.php?id=1\" title=\"Eric\">Eric</a>\ </div>\ "); //or $("ul#wall").prepend( "<div class=\"comment-main2\">" + " <div class=\"commentname\">" + " <a href=\"/profile/index.php?id=1\" title=\"Eric\">Eric</a>" + " </div>" ); Quote Link to comment https://forums.phpfreaks.com/topic/259018-prepend-multiple-lines/#findComment-1327903 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.