Make Text Selectable Inside an Unselectable Div

In my page i have made an entire div unselectable, with the help of this css (which i got from stackoverflow it self)

    .unselectable {
   -moz-user-select: -moz-none;
   -khtml-user-select: none;
   -webkit-user-select: none;

   /*
     Introduced in IE 10.
     See 
   */
   -ms-user-select: none;
   user-select: none;
}

Now i got an h2 tag inside this unselectable div.And i want that h2 to become selectable.Is there any way to achieve this easly.

I have forgot some thing in my question . i got three h2 in my code an i need specific one to be selectable so i added a class to this h2 and tried some thing like this .unselectable:not(.class-of-h2) (which i got from below answers).but its not working

3 Answers

Use for your h2 element

.unselectable h2{
 -moz-user-select: text;
 -khtml-user-select: text;
 -webkit-user-select: text;
 -ms-user-select: text;
 user-select: text;
}

See demo

2

Just add the below CSS

.unselectable h2 {
   -moz-user-select: text;
   -khtml-user-select: auto;
   -webkit-user-select: auto ;
   -ms-user-select: auto;
   user-select: auto;
 }

See the demo

you can use

     .unselectable:not(h2:nth-child(2)) {
      //your data
      } 

not can exclude the element from your list of selector
this can make your whole div unselectable except h2 element.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest