WestCoast_BC
asked on
span onclick not working if no string displayed
If I have:
How can I get the function to be triggered if there isn't any text in the span. Ie, if it looks like:
Thank you for any help you can provide
<span onclick="myfunc()">hello world</span>
myfunc is triggered if I click on the text: hello worldHow can I get the function to be triggered if there isn't any text in the span. Ie, if it looks like:
<span onclick="myfunc()"></span>
Thank you for any help you can provide
A span with no content has no width and therefore nothing to click on. You'd need to put at least something, perhaps a non-breaking space character in there. Alternatively, you could use CSS to set a minimum width but you might also have to change the span's display property to inline-block to get that to work.
Depends on what you are trying to achieve... even a hidden button would non work like that as Russ has already said, you'll need some dimensions otherwise the element would have a height and width of zero.
You could either add width and height to your span or put another element within the span like an image but that's then another bunch of bytes to load. Adding a colour background would give it the appearance of a button or change your SPAN to a block level element like DIV or one of the headings, H1-H6.
Easier still, change it to a BUTTON which wouldn't necessarily need the background colour option.
<button type="button" style="width:60px; height: 20px;" onclick="myfunc()"></butto n>
You could either add width and height to your span or put another element within the span like an image but that's then another bunch of bytes to load. Adding a colour background would give it the appearance of a button or change your SPAN to a block level element like DIV or one of the headings, H1-H6.
Easier still, change it to a BUTTON which wouldn't necessarily need the background colour option.
<button type="button" style="width:60px; height: 20px;" onclick="myfunc()"></butto
ASKER
I have a table that includes a column of text. I want the user to be able to click on the text and edit it. Some cells may not contain any initial text but I want the user to be able to select the cell and edit the text. A button does not work for me since I want to show the cell empty if there isn't any text.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. I was missing the inline-block which was why the min-height an min-width was not working