3

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

    }
})

2 Answers 2

3
+50

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.

Sign up to request clarification or add additional context in comments.

7 Comments

if the #lblQ1Doc had use the session ?
What do you mean “use the session”?
because previously I had set the #lblQ1Doc with session
I do not quite understand, do you mean window.sessionStorage? Or what session could be in Javascript?
window.sessionStorage
|
0

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

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.