Eng Soon Cheah
Eng Soon Cheah

Reputation: 257

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>');

    }
})

Upvotes: 3

Views: 165

Answers (2)

nvidot
nvidot

Reputation: 1412

From what I understand, having read your other post, you have stored some data in the WebStorage using C#.

And now you want to remove that same data from within the browser using Javascript ?

If so, what you want to use is1:

sessionStorage.removeItem('key_to_your_data');

Upvotes: 0

R0l
R0l

Reputation: 434

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.

Upvotes: 3

Related Questions