Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove File and value from Javascript

May I ask about how can I remove the value of q , when the class .close is clicked? Here with my source code:

$(document).on('click', '.close', function () {
    $(this).parents('p').remove();

})

$('#Q1DocPath').change(function () {

    var path = $(this).val();

    if (path != '' && path != null) {
        var q = path.substring(path.lastIndexOf('\\') + 1);

        $('#lblQ1Doc').html('<br/>' + '<p>' + q + '<a class="close"><font color="red">x</font><a>' + '</p>');

    }
})

like image 374
Eng Soon Cheah Avatar asked Jun 18 '26 08:06

Eng Soon Cheah


1 Answers

If I understand the question correctly you need to remove the value of q only from HTML. The easiest way is to wrap the value with the span tag.

$(document).on('click', '.close', function () {
    $(this).prev('span').remove();

})

$('#Q1DocPath').change(function () {

    var path = $(this).val();

    if (path != '' && path != null) {
        var q = path.substring(path.lastIndexOf('\\') + 1);

        $('#lblQ1Doc').html('<br/>' + '<p><span>' + q + '</span><a class="close"><font color="red">x</font><a>' + '</p>');

    }
})

Let me know if you needed something else or injected HTML can't be modified, I'll correct the answer.

like image 116
R0l Avatar answered Jun 20 '26 22:06

R0l



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!