I have a question:
Is there any way to show the ID
when you are hovering over a paragraph?
I made a fiddle to explain it.
Hope you guys know if it's possible.
Thanks!
I have a question:
Is there any way to show the ID
when you are hovering over a paragraph?
I made a fiddle to explain it.
Hope you guys know if it's possible.
Thanks!
If you are after setting p contents when you hover over the link, then you'll use onmouseover. Get the p element and set the innerText/innerhtml in JavaScript
<a href="somepage.php?id=3" data-id="3" onmouseover="document.getElementById('ptag').innerHtml(this.getAttribute('data-id'))">hover</a>
<p id="ptag"></p>
However, this way doesn't parse the url of the link
<a href="somepage.php?id=3" data-id="3" onmouseover="document.getElementById('ptag').innerHtml(this.getAttribute('href'))">hover</a>
<p id="ptag"></p>
This will show the link to the user in the p tag.
How can I get query string values in JavaScript?
This link will help you parse the url and get the id value from the link
Pure CSS solution: you can use :after
psudo element in combination with the attr()
css function.
#name_1 {
background-color: gold;
}
#name_2 {
background-color: skyblue;
}
#name_1:hover::after {
content: attr(id);
position: absolute;
font-size: 2em;
font-weight: bold;
color: red;
background-color: lavender;
}
#name_2:hover::after {
content: attr(id);
position: absolute;
font-size: 2em;
font-weight: bold;
color: red;
background-color: lavender;
}
<p id=name_1>text text text text<br> text text text text </p>
<p id=name_2>text text text text<br> text text text text </p>
To get, the ID from the query string
and not the id of the element (http://jsfiddle.net/9L2ns0nL/5/),
you can use jquery $(this).attr('href')
and then split the resulting string according to the url pattern.
see: http://jsfiddle.net/9L2ns0nL/9/
No confusing variables names next time.