HTML element does not remove jquery with name containing backslash

I am trying to remove a DOM element by finding it in a property data-value. And I have a problem when this property contains the character '\'. Example:

<li class="tag" data-value="test\image">
     <span>test\image</span>
     <input type="text" value="test\image">
     <i class="reset-clear-icon small"></i>
</li>

In my JS code, the element is deleted like this:

...
//passing tag selector here
$tag.remove();
...

Is there any approach for a method to remove()work for backslash data? And in order for the data to be displayed correctly, without encoding a backslashcharacter in html, like this

$tag.replace("\\", "&#92")

so that it appears in html test\image.

+4
source share
2 answers

\\\\ \ JQuery :

$("li[data-value='test\\\\image']").remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<li class="tag" data-value="test\image">
     <span>test\image</span>
     <input type="text" value="test\image">
     <i class="reset-clear-icon small"></i>
</li>
Hide result

HTML- .

+1

,

$(".tag").data([value="test\image"]).remove();

jsFiddle

0

Source: https://habr.com/ru/post/1609489/


All Articles