Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:31:01+00:00 2026-06-04T02:31:01+00:00

i have html page with a link when user clicked that link a new

  • 0

i have html page with a link

when user clicked that link a new select tag should be appeared

html code

<div class="container" id="addCell">
    <ul class="containerUL">
        <li class="containerLI">
            <p>
                <label>Name</label>
                <input type="text" class="longInput1"/>
            <p>
            <p>
                <label>City</label>
                <select id="countrySelector">
                </select>
            </p>
        </li>
        <li class="containerLI">
            <p>
                <label>Inserted cells</label>
                <a href="#" class="smallLink" id="acaclink">new</a>
            </p>
        </li>
        <li class="containerLI">
            <input type="submit" class="button1" value="save"/>
        </li>
    </ul>
</div>

jquery code

$("#addCell").ready(function(){
    $("#addCell").on('click',"#acaclink",function(){
        $.getJSON("http://localhost/Mar7ba/Cell/getAllCells/TRUE",function(data){
            var options = '';
            options+="<option>select cell</option>";
            for(var i=0;i<data.length;i++){
                options += "<option>"+data[i]+"</option>";
            }
            $(this).closest('li').append('<p>\n\
            <label>Select Cell</label>\n\
            <select name="acSelect[]">\n\
             '+options+'\n\
</select>\n\
            </p>');
        });
    });
});

1- i am check the JSON call and there is no error
2- i am alert option and it works as i want

my question is : when i replace $(this).closes('li') with $('ul').append
it works , but when i put closest li it doesn’t . where is the mistake please

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:31:03+00:00Added an answer on June 4, 2026 at 2:31 am

    That’s because $(this) inside anonymous function has another scope and refers to another object

    $("#addCell").ready(function(){
        $("#addCell").on('click',"#acaclink",function(){
            var me = this; // we use "me" as a closure to the object we clicked at
    
            $.getJSON("http://localhost/Mar7ba/Cell/getAllCells/TRUE",function(data){
                var options = '';
                options+="<option>select cell</option>";
                for(var i=0;i<data.length;i++){
                    options += "<option>"+data[i]+"</option>";
                }
                $(me).closest('li').append('<p>\n\   // <---- here we use "me"
                <label>Select Cell</label>\n\
                <select name="acSelect[]">\n\
                 '+options+'\n\
    </select>\n\
                </p>');
            });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a html page that contains a structure like this: <table class=pick> <tr>
I have an html page which contains a div that displays the html from
I have an HTML web page (the parent) that contains a hyperlink. When clicked,
i am new user to php and i have a html page which is
I have the below HTML in my page <div id='divContainer1' onmouseover=ShowEditDiv(1) onmouseout=HideEditDiv(1) class='divClcContainer'> <div
I have an html page with a link like this: <a href=javascript:window.print()>Print QR code</a>
I have an html page which has a link called open. Once the link
I have an link in HTML and I use Page Object pattern to write
I have an HTML link that opens a jQuery modal dialog which contains an
I have an html page full of images. Currently, each image is a link

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.