/    Sign up×
Community /Pin to ProfileBookmark

preventDefalut()

case 1:

[code=html]
var viewMore = ‘<span class=”view-more”>view more<span>’;
[/code]

case 2:

[code=html]
var viewMore = ‘<a class=”view-more” href=”#”>view more<span>’;
[/code]

jQuery(‘.view-more’).click(function(){
console.log(jQuery(this).next());
}

in case 1 the result is the next element, after ‘.view-more’ which Is what I expect.
However, in case 2, the result is not the next element, but the link itself. WHYYYYYYYY

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@rootMar 03.2017 — and its a JQuery question that belongs in the JavaScript Frameworks forum...
Copy linkTweet thisAlerts:
@Kevin2Mar 03.2017 — in case 1 the result is the next element, after '.view-more' which Is what I expect.

However, in case 2, the result is not the next element, but the link itself. WHYYYYYYYY[/QUOTE]


Because the link is doing what it's supposed to do, go to the URL specified in the [B]href[/B] attribute, in this case the top of the page. Incidentally, and maybe helpfully, the [B]href[/B] attribute is NOT required on the <a> tag. Leave it off and see what happens.
×

Success!

Help @brsastre spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...