Reputation: 87
I have this set of code that will be links to sections of the hta page:
<ul>
<li><strong>Windows 10</strong> comes with a new design and features.</li><br><br>
<li><strong><a href="#" class="startLinks" id="Edge">Microsoft-Edge</a></strong> has been introduced as Microsoft's next generation web browser.</li><br><br>
<li><strong><a href="#" class="startLinks" id="Skype">Microsoft Skype for Business</a></strong> is the Lync that you know . </li><br><br>
<li><strong><a href="#" class="startLinks" id="FindPrinter">Printer list</a></strong> ........... </li><br><br>
<li><strong><a href="#" class="startLinks" id="Email">Email Signature</a></strong> ........... </li>
</ul>
I want Microsoft edge, Microsoft skype for business, printer list, and Email signature to be the links and depending on which link is clicked the JavaScript will use slider.gotoslide(x)
here:
$('div.Welcome a').click(function(){
var itemClicked = 'div.Welcome a';
if (itemClicked.index() === 0){ //Microsoft Edge
slider.goToSlide(6); //slide 6
}
else if (itemClicked.index() === 1) { //Microsoft Skype for Business
slider.goToSlide(10); //slide 10
}
else if (itemClicked.index() === 2) { //Find and Add Printers
slider.goToSlide(15); //slide 15
}
else if (itemClicked.index() === 3) { // Email Signature
slider.goToSlide(11); //slide 11
}
return false;
});
As you can see I need the div.welcome a
to give me which link was clicked on and then the if statements to tell me which slide to go to. However index is saying that
Object doesn't support property or method "index"
Upvotes: 2
Views: 81
Reputation: 218852
Use $(this)
.
With the above expression you are converting/wrapping the element invoked (this
) (clicked anchor tag in this case) with jQuery. So the result of this expression will be a jQuery object.
$(function(){
$('div.Welcome a').click(function(e){
e.preventDefault(); //prevent default link click behaviour
var itemClicked = $(this);
var id = itemClicked.attr("id"); //get the Id of the clicked a tag
alert(id);
//use id for your further code now
});
});
Here is a working jsBin sample.
Upvotes: 5
Reputation: 157
I feel like all you need to change is
var item = 'div.welcom a' to $('div.Welcome a');
Upvotes: 0