1

I'm working with a CMS which allows you to add a tooltip to input boxes.

So this one has tooltip "Please enter your phone number".

<input name="var_customerphone" title="Please enter your phone number" />

and this one is emtpy

<input name="var_customername" title="" >

Here's my css which changes the cursor to help

input[type="text"][title] { cursor: help; } 

My problem is this, the above code will show the help cursor for both inputs above, even though the second one doesn't contain any help text in the tooltip.

Is there any way to put some conditional code on the css to only show the help cursor if title is not empty?

Something along the lines of: input[type="text"][title !=""] { cursor: help; }

I have no control over the CMS so title will be outputted regardless if it contains any text or not.

thanks

1
  • You could use JavaScript to detect the empty titles and apply a class that controls the behavior of the hover state. Commented Feb 5, 2014 at 13:43

2 Answers 2

5

Try this:

input[type="text"]:not([title=""]) { cursor: help; }

Note: According to w3schools, IE8 and earlier do not support the :not selector.

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

1 Comment

To improve your question add the compatibility of that selector
4

Without using :not and increasing a bit compatibility with older browser (it works also on IE7):

input[type="text"][title] { 
  cursor: help; 
} 

/* revert style for empty titles */
input[type="text"][title=""] { 
  cursor: default; 
} 

example: http://codepen.io/anon/pen/LdGiq

1 Comment

you're welcome: of course :not would be my choice too, but unfortunately IE8 still has too many users

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.