change cursor to finger pointer - html

I have this a and I don't know that I need to insert into the "onmouseover" so that the cursor will change to finger pointer like a regular link:
<a class="menu_links" onclick="displayData(11,1,0,'A')" onmouseover=""> A </a>
I read somewhere that I need to put:
onmouseover="cursor: hand (a pointing hand)"
But it's not working for me.
Plus I'm not sure if this is considered JavaScript, CSS, or just plain HTML.

<a class="menu_links" onclick="displayData(11,1,0,'A')" onmouseover="" style="cursor: pointer;"> A </a>
It's css.
Or in a style sheet:
a.menu_links { cursor: pointer; }

You can do this in CSS:
a.menu_links {
cursor: pointer;
}
This is actually the default behavior for links. You must have either somehow overridden it elsewhere in your CSS, or there's no href attribute in there (it's missing from your example).

I like using this one if I only have one link on the page:
onMouseOver="this.style.cursor='pointer'"

in css write
a.menu_links:hover{ cursor:pointer}

Here is something cool if you want to go the extra mile with this. in the url, you can use a link or save an image png and use the path. for example:
url('assets/imgs/theGoods.png');
below is the code:
.cursor{
cursor:url(http://www.icon100.com/up/3772/128/425-hand-pointer.png), auto;
}
So this will only work under the size 128 X 128, any bigger and the image wont load. But you can practically use any image you want! This would be consider pure css3, and some html. all you got to do in html is
<div class='cursor'></div>
and only in that div, that cursor will show. So I usually add it to the body tag.

I think the "best answer" above, albeit programmatically accurate, does not actually answer the question posed. the question asks how to change the pointer in the mouseover event. I see posts about how one may have an error somewhere is not answering the question. In the accepted answer, the mouseover event is blank (onmouseover="") and the style option, instead, is included. Baffling why this was done.
There may be nothing wrong with the inquirer's link. consider the following html:
<a id=test_link onclick="alert('kinda neat);">Click ME!</a>
When a user mouse's over this link, the pointer will not change to a hand...instead, the pointer will behave like it's hovering over normal text. One might not want this...and so, the mouse pointer needs to be told to change.
the answer being sought for is this (which was posted by another):
<a id=test_link onclick="alert('Nice!');"
onmouseover="this.style.cursor='pointer';">Click ME!</a>
However, this is ... a nightmare if you have lots of these, or use this kind of thing all over the place and decide to make some kind of a change or run into a bug. better to make a CSS class for it:
a.lendhand {
cursor: pointer;
}
then:
<a class=lendhand onclick="alert('hand is lent!');">Click ME!</a>
there are many other ways which would be, arguably, better than this method. DIVs, BUTTONs, IMGs, etc might prove more useful. I see no harm in using <a>...</a>, though.
jarett.

Add an href attribute to make it a valid link & return false; in the event handler to prevent it from causing a navigation;
A
(Or make displayData() return false and ..="return displayData(..)

Solution via pure CSS
as mentioned in answer marked as the best
is not suitable for this situation.
The example in this topic does not have normal static href attribute,
it is calling of JS only, so it will not do anything without JS.
So it is good to switch on pointer with JS only.
So, solution
onMouseOver="this.style.cursor='pointer'"
as mentioned above (but I can not comment there) is the best one in this case.
(But yes, generaly, for normal links not demanding JS, it is better to work with pure CSS without JS.)

<! –– add this code in your class called menu_links -->
<style>
.menu_links{
cursor: pointer;
}
</style>
In the above code [cursor:pointer] is used to access the hand like cursor that appears when you hover over a link.
And if you use [cursor: default] it will show the usual arrow cursor that appears.
To know more about cursors and their appearance click the below link:
https://www.w3schools.com/cssref/pr_class_cursor.asp

div{cursor: pointer; color:blue}
p{cursor: text; color:red;}
<div> im Pointer cursor </div>
<p> im Txst cursor </p>

Related

Selenium---can't click on an image

I have this function and i am not able to click on all of the magnifying glasses from a page. I have tried until now, by using different alternatives. What is commented, is what i tried until now.
def lupa():
elements = browser.find_elements_by_css_selector("a[onclick='return Go(event, 2)'] > img[title='Details']")
for element in elements:
#element.click()
element.send_keys(Keys.SPACE)
time.sleep(1)
Please see below how looks the HTML code.
<a href="#" onclick="return Go(event, 2)">
<img title="Details" src="/common/images/Detail.gif">
</a>
This are the old XPATHs i used in order to click on the image.
#browser.find_element_by_xpath(".//*[#id='resultsTable']/tbody/tr[17]/td[11]/a[2]/img").click()
#lupa = browser.find_element(By.XPATH("//img[#src='/common/images/Detail.gif']"))
#lupa = browser.find_element(By.cssSelector("a[src='/common/images/Detail.gif']"))
#lupe = browser.find_elements_by_css_selector("a[src='/common/images/Detail.gif']"))
#lupa=browser.find_element_by_link_text("Details").click()
#lupa= browser.find_element_by_id("Details").click()
#elements = browser.find_elements_by_css_selector("a[src='/common/images/Detail.gif']"))
Thank you for your answer!
Cohen
Most of the locators you tried aren't valid. You probably should spend some time learning about the different locator types and how they work.
Given the HTML, the CSS selector below should find the IMG tag(s) you want.
img[title='Details']
Another thing, you are not using implicit wait correctly. It's set once for the life of the driver. Calling it over and over does nothing. You don't want to use implicit wait, use an explicit wait instead. Look at some tutorials for WebDriverWait.
EDIT: Clicking the IMG tag should work just find since it's surrounded by the desired A tag. But... if you need to click the A tag specifically, you should be able to use the locators below.
More specific CSS selector
a[onclick='return Go(event, 2)'] > img[title='Details']
XPath
//a[#onclick='return Go(event, 2)'][./img[title='Details']]

Is it possible to modify "href" in a stylesheet?

I would like to move the href assignment to CSS.
Something like <a style="href: url('Home.htm');">Home</a> instead of Home.
Is it possible to do this in CSS?
I have a button at several places in my site whose corresponding URL value, might change in the future. I want to change the target address only in one place, i.e. my CSS file, instead of having to manually change them for every instance of that button.
This behaviour isn't really supported, as explained in other answers. But if you really need this on a page, it's possible to add it using some JavaScript. Used-defined custom variables/properties in CSS need to start with --, and I'll use the name --href-override.
We'll listen for all mousedown and touchstart events on links in the document. These events are useful because they'll always occur before the click is registered. Each time we handle one of these events, we check if the associated link has a --href-override property/variable defined in CSS. If so, we replace the HTML href with the CSS --href-override value, and the browser will automatically use that new value when handling the click event.
function overrideEventTargetHref(event) {
// if it's the beginning of a click on a link...
if (event.target.tagName === 'A') {
var link = event.target;
var override = getComputedStyle(link).getPropertyValue('--href-override').trim();
// if the link has an CSS href-override and it's different than the HTML href...
if (override && override != link.href) {
// replace the HTML href with the CSS href-override
link.href = override;
}
}
}
window.addEventListener('mousedown', overrideEventTargetHref, false);
window.addEventListener('touchstart', overrideEventTargetHref, false);
.override {
--href-override: https://stacksnippets.net/;
}
actually example.com
secretly stacksnippets.net
This also work properly for things like middle-clicking to open in a new tab.
This is quite a hack and you usually wouldn't want to do it. But if your situation requires it, you can.
CSS is a styling sheet, so the short answer is no. Also not entirely sure as to what your reason for wanting to is, but if it's due to changing data, use JavaScript or PHP to do this instead. Much easier, logical, and possible.
The href property stands for hypertext reference. It is not an entity that lends itself to styling; see this resource. If you wish to style how that location's text value appears on a page, you could write code that styles the a tag and if you want to get fancier you could add on a pair of span tags, as follows:
CSS:
a {
font: 14px Arial,Helvetica;
color: #00c;
text-decoration:none;
border: 4px dotted #009;
}
a:hover {
border: 3px solid #009;
}
span {
color: #f0f;
}
<span>Home</span>
As for changing the values of the buttons, if you run Linux, it provides various helpful utilities, such grep; see this discussion. Also, see this article.

What is the default cursor icon for delete?

In the process of building an app and I was setting it up so when you hold the control key and click on a checkbox it would change to a remove (x) rather than an add (✓).
I am able to add a class to my element when the keydown occurs and remove it when the keyup occurs. I also have it working on the click, however the problem I'm running into is I want to show a delete/remove cursor.
I know we have default icons for many things including adding something, but I can't seem to find anything for deleting/removing. Does anyone have a valid method of showing delete, other than building your own icon? I would like to avoid this, as each browser/os has different icons. Thus far other than creating my own icon, it seems like no-drop might be my closest choice?
Is there something I'm missing, hopefully someone has a better method of handling this than I do that would work with chrome/IE/FF/safari?
https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
.add-item { cursor: copy; }
.remove-item { cursor: ????; }
There isn't one but you can create your own icon and use cursor: url(); CSS to accomplish this.
More info here: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_User_Interface/Using_URL_values_for_the_cursor_property
Example:
div {
cursor: url("https://i.stack.imgur.com/bUGV0.png"), auto;
}
<div>Hover Here</div>
not-allowed is the only one that makes sense, however the custom jpg url option looks pretty simple.
You could also rethink your UI design to get around this. You could just stick with the intuitive default behavior of a checkbox, and let the user click it with the understanding that the checkmark will toggle. No fancy control key, no fancy cursors. Maybe just a pointer icon in either case. With some separate add / remove action buttons.
You could also think about showing some clickable icons for add / remove (per item if applicable). Thus not using a checkbox.
Here is a list of cursor properties.
cursor: not-allowed seems to be the only one similar to a "deleted" property. Example.
You can also use the url property to insert your own custom image.
There are multiple options to get the expected result.
However it's not the default option, using cursor: url() to display a custom image should work fine.
Otherwise use one of the default properties, of which not-allowed is probably the best option.
More about cursor properties
Default cursors:
<p>Mouse over the words to change the cursor.</p>
<span style="cursor:auto">auto</span><br>
<span style="cursor:crosshair">crosshair</span><br>
<span style="cursor:default">default</span><br>
<span style="cursor:e-resize">e-resize</span><br>
<span style="cursor:grab">grab</span><br>
<span style="cursor:help">help</span><br>
<span style="cursor:move">move</span><br>
<span style="cursor:n-resize">n-resize</span><br>
<span style="cursor:ne-resize">ne-resize</span><br>
<span style="cursor:nw-resize">nw-resize</span><br>
<span style="cursor:pointer">pointer</span><br>
<span style="cursor:progress">progress</span><br>
<span style="cursor:s-resize">s-resize</span><br>
<span style="cursor:se-resize">se-resize</span><br>
<span style="cursor:sw-resize">sw-resize</span><br>
<span style="cursor:text">text</span><br>
<span style="cursor:w-resize">w-resize</span><br>
<span style="cursor:wait">wait</span><br>
<span style="cursor:not-allowed">not-allowed</span><br>
<span style="cursor:no-drop">no-drop</span><br>
Source
I suggest no-drop or not-allowed .

How to add disabled attribute to input tag with ngTagsInput?

I have a custom directive that I use to manage user access through my website. I use this to add a 'disabled="disabled"' attribute to html tags.
However, when I try to use this with tag-input, it doesn't work. I'm guess this is down to that fact that ngTagsInput uses it's own directive for tags-input.
I have read the documentation and cannot find a solution to what I am looking for.
Here is my code:
Html:
<div access-level="Admin">
<tags-input ng-model="tags" on-tag-added="addNewTag($tag)" on-tag-removed="removeTag($tag)">
<auto-complete source="loadTags($query)" min-length="0"></auto-complete>
</tags-input>
</div>
Is there any work around for this?
Thanks.
It's currently unsupported, but looks like will be in the next major version (2.3.0):
https://github.com/mbenford/ngTagsInput/issues/102
Edit:
2.3.0 is out; see following link for details https://github.com/mbenford/ngTagsInput/blob/master/CHANGELOG.md#features
I could not find this option in the release 2.3.0, but at least they have enabled the regular disabled attribute.
What I have done to hide the remove button and the "Add a tag" input box, was to add a couple of rules in the CSS.
tags-input[disabled] .remove-button {
display: none;
}
tags-input[disabled] input.input {
display: none;
}
Probably there is a better way to do it, this was the fastest I could find.

Using CSS to selectively hide information

I have a table that displays information about a list of customers. I want to selectively hide certain fields of information in different pages. Is it a good practice to simply define each page as a different ID and use CSS to control what is shown. Or should I actually go into the controllers and models to control it.
For example, each customer has 3 pieces of information to it: name, phone number, address and the html, css mark up is as follows:
<style>
#SomeSpecificPage span.text-phonenumber { display: none }
</style>
<div id="SomeSpecificPage">
<span class="text-name"><% name %></span>
<span class="text-phonenumber"><% phone number %></span>
<span class="text-address"><% address %></span>
</div>
That is not a problem. Many people apply the page ID to the body element instead, but the practice is similar and isn't something naughty.
It's up to you whether you want to use CSS with page IDs to hide the fields or control output with your server-side code. Either is fine.
You could use after: or before: with CSS3.
This takes a different approach but may achieve what you're after. This should at least keep it out of sight from web crawlers which is what I imagine is what you want to achieve by hiding it. See Fiddle:
.text-name:after{
content:'contenthere'
}
.text-phonenumber:after{
content:'phonenumberhere'
}
.text-address:after{
content:'addresshere'
}
http://jsfiddle.net/CPVeA/
Keep in mind browser support: http://caniuse.com/#feat=css-gencontent
For visibility, I like to create a class called .hidden { display: none; } and put that on the elements I want hidden by default. Then you can use whatever language to toggle that class.
It depends on how you define "hide"... If a web-literate viewer views your source they can see everything hidden with css. Is that a problem? If not, go for it. Its a simple and effective solution.
On the other hand, is it confidential information that will get you in trouble? If so, don't even let it render, as in: alter the controls.