Hidden text can be selected in IE despite style='display:none'

后端 未结 3 1917
孤独总比滥情好
孤独总比滥情好 2020-12-19 06:10

This appears to be an IE-specific \'feature\'. I tested using IE8. User John H has contributing by confirming in IE6 and IE7.

I have some text that gets built into

相关标签:
3条回答
  • 2020-12-19 06:43

    The size display and position of the element doesn't matter, it's being selected because when you select things in IE<9, you are selecting html and then pasting that html, with hidden elements. IE9 and other browsers properly remove those hidden elements from the selection. The only way i know of to prevent it is to not have the hidden element in the dom.

    0 讨论(0)
  • 2020-12-19 06:44

    I think it's better if you use:

    position: absolute; left: -10000px;
    

    That will eliminate any potential IE problems.

    0 讨论(0)
  • 2020-12-19 06:45

    Have you tried the visibility:collapse property?

    If the "Value I want hidden" part is used purely for computational purposes, you should use the "data" attribute.

    Like this

    <div data-custom-value="1001">Visible value </div>
    

    In jQuery, HTML data attributes are automatically available via the data() api.

    You can do

    someElement.data('customValue') to read a value.

    and

    someElement.data('customValue', newValue) to set a value.

    Hope I analyzed your problem correctly.

    0 讨论(0)
提交回复
热议问题