OK, so jQuery is making more and more sense with everyday. I'm using it with more confidence and experiencing less errors, and needing to pop my head up in this forum less often. But today I've found something I need a bit of help with, and I'd be very grateful for a bit of wisdom:
I have a long string of html that I want to insert with the .before function. It works, but only if I put all the html on one line, which makes for some pretty ugly code, which is a real pain to edit. I'd like to be able to put the html in a separate file, presented in a clean and clear way, which jQuery then inserts .before a specified div.
Here's the working but ugly code I have right now (line 7 is where the magic happens):
- $(function() {
- $('#addnew').click(function(event){
- $('.full-width').toggleClass('grey')
- $('#addnew').closest('.full-width')
- .before('<div class="row full-width"><div class="gridfix"><div class="medium-12 columns center section"><h1> What\'s your question?</h1><input type="text" placeholder="ask here" id="askquestion" name="qtitle" /></div></div></div><div class="row full-width hidden" id="type"><div class="triangle"> </div><div class="gridfix"><div class="medium-12 columns section center"><h1> What kind of question is it? </h1><a class="button multi">Multiple Choice with one answer</a><a class="button multi">Multiple Choice tick all that apply</a><a class="button">Text Field</a><a class="button">Rating</a></div></div></div></div>')
- })
- })
and here's the code that I want to work, but won't:
- $(function() {
- $('#addnew').click(function(event){
- $('.full-width').toggleClass('.grey')
- $('#addnew').closest('.full-width')
- .before(function(event).load("../questionedithtml.html"))
- })
- })
Any pointers as to where I'm going wrong? Probably something embarrassingly fundamental, but that's learning.
Thanks a lot!