This question already has answers here:
How to select an element inside "this" in jQuery?
(2 answers)
Closed 6 years ago.
<script type="text/javascript">
jQuery(".post-entry").click(function() {
window.location = jQuery(this).find("a").attr("href");
return false;
});
</script>
Is it possible to modify this script to find a href link that has a specific class? The reason is that some of these divs have multiple links within.
Absolutely.
$('.post-entry').click(function() {
window.location = $(this).find('a.example-class').attr('href')
return false;
})
If you want a hand cursor, you'll need a bit of CSS too:
.post-entry {
cursor: pointer;
}
Related
This question already has answers here:
How to Disable the CTRL+P using javascript or Jquery?
(12 answers)
Closed 6 years ago.
I disabled right click and print option (ctrl+P ) and view source (ctrl+U) using javascript. Because of these restrictions keys U and P are not working.Please give me the solution or any alternative way to disable (ctrl+P and ctrl+U)option.
And here is my javascript code:
for print
if(cc.which == 85)
{
return false;
}
if(cc.which == 80)
{
return false;
}
for right click
status="Right Click Disabled";
function disableclick(event)
{
if(event.button==2)
{
alert(status);
return false;
}
}
You can't prevent the user from printing, but you can hide everything when the user prints the document by using simple CSS:
<style type="text/css" media="print"> * { display: none; }</style>
You can't prevent the user from printing, but you can hide everything when the user prints the document by using simple CSS:
<style type="text/css" media="print">
* { display: none; }
</style>
refer : How to disable printing options in the browser for certain pages
How to Disable the CTRL+P using javascript or Jquery?
This question already has answers here:
How to add click event to a iframe with JQuery
(13 answers)
Closed 8 years ago.
How to capture click on iframe using javascript.
I'm using this code:
document.getElementsByClassName('pin').contentWindow.document.body.onclick =
function() {
alert("iframe clicked");
}
But it is not able to capture any click of the iframe. I can only use javascript.
I'm getting this error
"SecurityError: Blocked a frame with origin"
var i = 0;
//i represents the exact node since obtaining node by class name gives array of nodes.
var iframe = document.getElementsByClassName('pin')[i].contentWindow;
or
var iframe = document.getElementById("iframe_id").contentWindow;
iframe.document.body.onmousedown =
function() {
alert("iframe clicked");
}
This question already has answers here:
jQuery : how to determine that a div is scrolled down
(7 answers)
Closed 9 years ago.
I want to call ajax function while scrolling inner scroll and append the results at the bottom of the existing results.
For refrence I've attached an image here.
How can I achive this?
You can use something like this without jQuery also
window.onload = function(){
if(window.addEventListener){
document.addEventListener('DOMMouseScroll', moveObject, false);
}
var myDiv = document.getElementById("myDiv");
myDiv.onmousewheel = ajaxFunction();
}
This question already has answers here:
Detect if browser supports contentEditable?
(5 answers)
Closed 10 years ago.
I want to check whether the "contenteditable" or any HTML5 property is supported by user browser or not ?
So here is my JavaScript:
var isEditable=false;
function chk() {
var z=document.getElementById("mydivid");
if(typeof(z["isContentEditable"])==="boolean") {
isEditable=true;
}
}
function doEdit() {
chk();
var z=document.getElementById("mydivid");
if(isEditable) {
z.setAttribute("contenteditable","true");
z.focus();
} else {
/* add a texbox and put all div's innerHTML into it, All in all: a Boring Stuff. */
}
}
And Here is HTML:
Click To Edit
<div id="mydivid"> Hi Ssup ?? <img src='' alt="some image" /></div>
Can Anyone tell me Whether My Approach is right ? Will it work in IE(version<8.0) ? And Also A better approach is needed !
Simple check:
if ('isContentEditable' in document.createElement('span')) {
// supported
}
I will also share this great selection of snippets it will help you in future: http://diveintohtml5.info/everything.html
To chcek if any propery exits for a element. You can do this
var element = document.createElement('__ELEMENT__');
if ('__PROPERTY__' in element ) {
// property supported in the browser
}
or
if ('__PROPERTY__' in document.createElement('__ELEMENT__') ) {
// property supported in the browser
}
The below link contains it all.
https://github.com/Modernizr/Modernizr/issues/570
http://diveintohtml5.info/everything.html#contenteditable
This question already has answers here:
How do I disable a href link in JavaScript?
(20 answers)
How do you make an anchor link non-clickable or disabled?
(19 answers)
Closed 6 years ago.
I have to disable anchor link depending on a condition if some data comes to that field it should work as a hyperlink and if that data does not come then the link should not be there?
Any ideas on this are welcome.
Case 1:
To disable:
document.getElementById(id).style.pointerEvents="none";
document.getElementById(id).style.cursor="default";
To enable:
document.getElementById(id).style.pointerEvents="auto";
document.getElementById(id).style.cursor="pointer";
Case 2:
If you want the link to be gone (not just disable it):
document.getElementById(id).style.display="none";
to get it back:
document.getElementById(id).style.display="block"; //change block to what you want.
Case 3:
If you want to hide it preserving the space for it:
document.getElementById(id).style.visibility="hidden";
To get it back:
document.getElementById(id).style.visibility="visible";
I couldn't make sense of your question body, so I'll answer your question's title...
How to disable anchor using javascript ?
JavaScript
if (condition) {
document.getElementsByTagName('a')[0].removeAttribute('href');
}
jQuery
...because everyone uses it, right?
if (condition) {
$('a').first().removeAttr('href');
}
with jQuery
if(!data){
$('#linkID').click(function(e) {
e.preventDefault();
});
}
with Prototype
if(!data){
$('linkID').observe('click', function(event) { event.stop() });
}
my link
function check(){
var data =document.getElementById("yourdatafield").value;
if(data)
window.location="your_link_location";
}
With jQuery:
To disable:
$('#anchor_tag').attr("disabled", true);
To enable:
$('#anchor_tag').attr("disabled", false);