EDIT: Solved
I am building a website in wordpress and am currently editing a jquery plugin to return the clicked link's url in an alert box but it is returning undefined. This is only suppose to be trigger when clicking on one of the items in the navigation menu(which that part is working fine) see website link below for reference. Why is this happening?
snippet of code:
jQuery('body').on('click', '.start-pgm li', function() {
var addressValue = $(this).attr("href");
alert(addressValue );
$.window({ title: "Cyclops Studio", url: addressValue });
return false;
});
Additional information if it helps:
Web Address I am working on
Jsfiddle with whole script
shouldnt it be
.on('click', '.start-pgm li a', function()
You are registering a click listener on a <li> element which does not have a href attribute.
.start-pgm li
Related
There is a way to simulate a click on a link after having clicked another?
I have made this script:
$(".uno").click(function() {
$(".due")[0].click();
});
Fiddle: https://jsfiddle.net/5ad3m8La/
When I click on "one" want "two" open the page as indicated.
My script does not work, and I do not understand why.
Update your fiddle. Updated one https://jsfiddle.net/5ad3m8La/2/
Made few changes given below:
1. Added target="blank" in link.
2. Added http:// before google's link.
3. Wrapped your code in document.ready.
and it's working now :)
$(".uno").click(function(e) {
e.preventDefault();
location.href = $('.due').attr('href');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
One
Two
This is not the same as emulating a click, but this way the behaviour is the same as clicking another linke (without special code attached to it)
Try the code below:
$('.due').trigger('click');
Try this:
One
Two
jQuery:
$( ".uno" ).click(function() {
$('.due').trigger("click");
});
$( ".due" ).click(function() {
var link= $(this).attr("href"); // you need to ger href and redirect to that link
window.location.href = link;
});
I am trying to forward to a link when the div is clicked using a data attribute and jQuery, but am stuck a bit. Here is the code I have:
html:
<div class="clickable-icon" data-link="www.google.com">click to be forwarded</div>
jquery:
$('.clickable-icon').attr('data-link');
used google as an example for the link to go to. But how would I use jquery to help with this?
you can do:
window.location.href = $('.clickable-icon').data('link');
and as you want on click, write click event and get clicked element data-link attribute value:
$('.clickable-icon').click(function () {
window.location.href = $(this).data('link');
})
WORKING FIDDLE
You could use window.location.href like
$('.clickable-icon').on('click', function() {
window.location.href = $(this).data('link');
});
$('.clickable-icon').click(function(){
window.location.href = 'http://'+$(this).data('link');
})
I'm working on modifying a BigCommerce template and I want to change some text in the modal After it was launched.
I'm using jQuery to overcome these issues on the normal pages, but on the modal it doesn't work.
The next piece of code is used on 'ordinary' pages:
$(document).ready(function(){
$('.TopMenu li:contains("or")').each(function() {
var text = $(this).html();
$(this).html(text.replace('or', 'maybe'));
});
});
The next code Doesn't work for the modal:
$(document).ready(function(){
$("#ModalContainer").ready(function(){
$('#fastCartNumItemsTxt').each(function() {
var text = $(this).html();
$(this).html(text.replace('items','stuff'));
});
});
});
I'm trying to use:
$(".ProductActionAdd a").on( "click", function() {
$("#ModalContainer").ready(function(){
$('#fastCartNumItemsTxt').each(function() {
var text = $(this).html();
$(this).html(text.replace('items','stuff'));
});
});
});
Where ".ProductActionAdd a" represents the Add to Cart button which fires up the modal. Still doesn't work...
Any idea why?
I'd suggest just putting this script inside of the modal content panel in Bigcommerce, if you're looking for fast cart you can just go inside FastCartThickBoxContent.html
Other than that you'll have to use the iModal callback, which I am not familiar with.
Presently i am working on Colorbox plugin in website..
I have set of links in a page..(say links will be 50)..
This links holds the some data.. i.e, each link holds the one page. I want to display this page in colorbox when I am clicked the my link.
For this I am used the colorbox.. it works only for first link which I am clicked first.
if I clicked the another link in the same page the color box won't work.
It's show an error like..
Uncaught TypeError: Object [object Object] has no method 'colorbox'
I have link like this.
I used below code for calling colorbox.
$(document).ready(function () {
jQuery(".colorbox").on("click",function(event) {
console.log('i am here...');
event.preventDefault();
var elementURL = jQuery(this).attr("href"); var elementID = jQuery(this).attr("id");
jQuery("#"+elementID).colorbox({href: elementURL, innerWidth: 1000, innerHeight: 700});
});
});
I tried live also instead of on but I didn't get any result.
In my opinion, you don't need to initial colorbox every time when user clicked the link.
You should initial them at once and then these links will work as you expect.
HTML
<a class="color-anchor" href="http://www.bbc.co.uk/">BBC</a>
<a class="color-anchor" href="http://edition.cnn.com/">CNN</a>
JS
$(function(){
$("a.color-anchor").colorbox({href:$(this).attr("href") ,innerWidth: 700, innerHeight: 500, iframe:true});
});
Hope this is helpful for you.
I'm trying to figure out why my jquery isn't working correctly. I click on my navbar link and the content space shows for .0923202 of a second and goes back to be hidden. Thank you.
$(document).ready(function() {
$(".content").hide();
$("a").click(function() {
$(".content").show();
});
});
http://jsfiddle.net/NHgpg/
While anchor tags are meant to send users to another page, you're using it to show new content on the page. You will want to return false to override the default behavior of the anchor tag
$(document).ready(function() {
$(".content").hide();
$("a").click(function() {
$(".content").show();
return false;
});
});