I have hyperlinks, all of them are called "mylink". They should fire the same event, but only the first element with the name "mylink" actually fires. My code is as follows:
$(document).ready(function() { $("#formID").validationEngine() $('#mylink').click(function(e){ var goto = $(this).attr('href'); //get the url $.ajax({ url: goto }); //execute the href e.preventDefault(); //prevent click $('#mylink').parent().parent().fadeOut("slow"); }); })
Where am I going wrong?
$(function(){ $("#formID").validationEngine(); // don't forget your semi-colons $(".mylink").click(function(e){ // ID should be unique, use classes instead e.preventDefault(); $.ajax({ url: $(this).attr("href") }); $(this).parent().parent().fadeOut("slow"); // refer to this as 'this' }); });
You cannot reuse the id value. This "id" can be used only once per page.
If you need several elements that need to be affected, use the "class" component:
<div id="uniqueString" class="makeMeMoo makeMePurple makeMeClickable"> <!-- whatever --> </div>
.
, , , , (# mylink), jquery .
$('a.mylink').click(function(e) {
Source: https://habr.com/ru/post/1731286/More articles:What are the differences and similarities between .NET languages? - .netWhich method will work best? (Or is there a difference in matter?) - performanceHow can I check eof in Perl? - perlDo you know a user management project in Java? - javaAndroid SDK and AVD Manager, racks and / or never end - androidTricky Javascript: how to get value from json dict inside array inside dict :) - jsonSimple regex to extract content between square brackets in jQuery - jqueryObjective-C iPhone - предупреждение YouTubePlugIn.webplugin/YouTubePlugIn - objective-cSQL - database log file compression - sql-server-2008Why are console.log consoles not showing up in my FireBug console? - debuggingAll Articles