jquery delete parent doesnt work on the whole Line! What am i doing wrong?

I used the last answer from this question to Add Lines to my Poll which i am creating in Symfony but the string i am appending is a bit longer then the one in the answer

('<div><input type="text" name="mytext[]"/><a href="#" class="delete">Delete</a></div>')

Mine looks like that (with twig, u don’t have to understand everything in there, important is only the line <div><a href="#" <class="delete">Delete</a></div>' at the bottom):

'<div class="ul-div"><ul class="lst-none">n' +
'    <li>n' +
'        {% for Field in lineArray %}n' +
'            <div class="{% if loop.first %}lineFieldFirst{% else %}lineField{% endif %}">n' +
'                {% if Field.getType() == "choice" %}n' +
'                    <select name="field_choice_{{ Field.getId() }}[]" id="field_choice_{{ Field.getId() }}">n' +
'                        {% for Fieldvalue in Field.getFieldvaluesBySO() %}n' +
'                            <option value="{{ Fieldvalue.getValue() }}">{{ Fieldvalue.getTranslationName(app.request.getLocale()) }}</option>n' +
'                        {% endfor %}n' +
'                    </select>n' +
'                {% elseif Field.getType() == "checkbox" %}n' +
'                    <label for="field_checkbox_{{ Field.getId() }}">{{ Field.getTranslationName(app.request.getLocale()) }}</label>n' +
'                    <input type="checkbox" id="field_checkbox_{{ Field.getId() }}" name="field_checkbox_{{ Field.getId() }}[]">n' +
'                {% elseif Field.getType() == "date" %}n' +
'                    <label for="field_date_{{ Field.getId() }}">{{ Field.getTranslationName(app.request.getLocale()) }}</label>n' +
'                    <input type="text" class="datepicker" id="field_date_{{ Field.getId() }}" name="field_date_{{ Field.getId() }}[]">n' +
'                {% elseif Field.getType() == "number" %}n' +
'                    <input type="number" id="field_number_{{ Field.getId() }}" name="field_number_{{ Field.getId() }}[]" min="0" value="0" required>n' +
'                {% elseif Field.getType() == "text" %}n' +
'                    <label for="field_text_{{ Field.getId() }}">{{ Field.getTranslationName(app.request.getLocale()) }}</label>n' +
'                    <input type="text" id="field_text_{{ Field.getId() }}" name="field_text_{{ Field.getId() }}[]">n' +
'                {% endif %}n' +
'            </div>n' +
'        {% endfor %}n' +
'        <div><a href="#" <class="delete">Delete</a></div>' +
'    </li>n' +
'</ul></div>'

Clearly the function

$(wrapper).on("click", ".delete", function(e) {
    e.preventDefault();
    $(this).parent('div').remove();
    x--;
})

does not work anymore because it only deletes the div around the <a> tags, but even when i:

  • remove the div around that
  • use parent('div.ul-div')
  • use parent('ul')
  • use parent('div').parent('div')

The Button doesn’t delete the whole Line!
What am i doing wrong here?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *