0

This function inserts a file upload field in a specific div

$(".add_file_field").click(function() {
    var qid = $(this).attr("rel");
    $(this).parent().before("<div id='p_holder'></div>");
    $("#p_holder").load("<?=site_url('survey/add_upload_field')?>", {
        'qid': qid 
    });
    return false;
});

It is triggered by clicking on the link in this snippet

<span class="add_field_wrap">
    <a rel="31" class="add_file_field" href="http://domain.com/kms/#">
        Add another file
    </a>
</span>

How can I get it to insert the content just before the span.add_field.wrap, ie. without specifying a specific container that will receive the content? The span and all other markup must stay in place; the point is that the user can add as many file upload fields as he wants.

Thanks

1
  • 1
    Your question is not very much clear. Commented Jul 23, 2011 at 14:29

4 Answers 4

2
$(".add_file_field").click(function(){
    var qid = $(this).attr("rel");
    var parent = $(this).parent();

    $.get("<?=site_url('survey/add_upload_field')?>", {'qid': qid }, function(data) {
        $(parent).before(data);  
    });

    return false;
});
Sign up to request clarification or add additional context in comments.

Comments

1

Is this what you want?

$('.add_field_wrap').before(required_html_content);

Comments

0
$(".add_file_field").click(function(){
    var qid = $(this).attr("rel");
    $(this).parent().before("<div id='p_holder'></div>");
    $("#p_holder").load("<?=site_url('survey/add_upload_field')?>", {'qid': qid },
      function(data){
         $("span.add_field_wrap").insertBefore(data);
    })
   return false;
});

Comments

0

Try this

$(".add_file_field").click(function(){
    var qid = $(this).attr("rel");
    if(!$("#p_holder").length){
      $(this).parent().before("<div id='p_holder'></div>");
    }
    $.get("<?=site_url('survey/add_upload_field')?>", {'qid': qid },
     function(response){ 
       $("#p_holder").append(response);
    });
    return false;
});

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.