Keypress won't trigger on all my social buttons, just one?











up vote
0
down vote

favorite












I am using the ShareThis library for a site I am working on. I want to make this site accessible, so that a user can tab through and hit enter and trigger a click event. Right now, when a user hits enter on any of the social media buttons, a console message shows up but it doesn't treat it like a click and open the sharing page.



This is working on only the last button, the email button. It opens the right modal (every other button opens a different page) but each one still prints out the console message. Here is my code, I am unsure why it is not working.



Here is my JS code:



$('.sharethis-body .keypress-click').each(function () {
$(this).keypress(function (e) {
var key = e.which;
if (key == 13) // the enter key code
{
$(this).click();
console.log("click");
return false;
}
return true;
});
});


And here is my HTML:



    <div class="sharethis-body">
<div class="sthoverbuttons-label"><span>Share</span></div>
<span tabindex="0" class='st_facebook_large keypress-click' displaytext='Facebook' aria-label='Facebook'></span>
<span tabindex="0" class='st_twitter_large keypress-click' displaytext='Tweet' aria-label='Twitter'></span>
<span tabindex="0" class='st_googleplus_large keypress-click' displaytext='Google +' aria-label='Google Plus'></span>
<span tabindex="0" class='st_linkedin_large keypress-click' displaytext='LinkedIn' aria-label='LinkedIn'></span>
<span tabindex="0" class='st_email_large keypress-click' displaytext='Email' aria-label='Email'></span>
</div>


Any help with this would be greatly appreciated!










share|improve this question
























  • I tried your example in a simple test file with your JS code in my onload() and just the html you have above in addition to <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>. I get the same problem. Only email works. I tried changing the order of the spans (email in the middle) and still only email worked. I then added an onclick() handler to the google span and it runs when I press ENTER on the google icon. So the click is being fired. So maybe the problem is in the sharethis.com javascript.
    – slugolicious
    yesterday










  • that's a great observation. it might be in the library! but why would it work when clicked and work with the email, but not with the enter keypress? it kills me that it is working with the email and not with anything else, because I know my code is working but not on every single button.... thank you @slugolicious !!
    – cpick
    yesterday












  • I hadn't tried mouse clicking on them. Indeed, all of them work for me too. I added this to the "each" loop after the keypress() declaration so that all the elements had an onclick: $(this).click(function (e) { alert('my click'); });. Pressing ENTER on all the elements runs the "my click" but only the email pops up a dialog. One other difference is email opens a dialog within the same page whereas all the others open a new browser window (when you click with the mouse). So there is some consistency as to the images that don't work.
    – slugolicious
    yesterday















up vote
0
down vote

favorite












I am using the ShareThis library for a site I am working on. I want to make this site accessible, so that a user can tab through and hit enter and trigger a click event. Right now, when a user hits enter on any of the social media buttons, a console message shows up but it doesn't treat it like a click and open the sharing page.



This is working on only the last button, the email button. It opens the right modal (every other button opens a different page) but each one still prints out the console message. Here is my code, I am unsure why it is not working.



Here is my JS code:



$('.sharethis-body .keypress-click').each(function () {
$(this).keypress(function (e) {
var key = e.which;
if (key == 13) // the enter key code
{
$(this).click();
console.log("click");
return false;
}
return true;
});
});


And here is my HTML:



    <div class="sharethis-body">
<div class="sthoverbuttons-label"><span>Share</span></div>
<span tabindex="0" class='st_facebook_large keypress-click' displaytext='Facebook' aria-label='Facebook'></span>
<span tabindex="0" class='st_twitter_large keypress-click' displaytext='Tweet' aria-label='Twitter'></span>
<span tabindex="0" class='st_googleplus_large keypress-click' displaytext='Google +' aria-label='Google Plus'></span>
<span tabindex="0" class='st_linkedin_large keypress-click' displaytext='LinkedIn' aria-label='LinkedIn'></span>
<span tabindex="0" class='st_email_large keypress-click' displaytext='Email' aria-label='Email'></span>
</div>


Any help with this would be greatly appreciated!










share|improve this question
























  • I tried your example in a simple test file with your JS code in my onload() and just the html you have above in addition to <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>. I get the same problem. Only email works. I tried changing the order of the spans (email in the middle) and still only email worked. I then added an onclick() handler to the google span and it runs when I press ENTER on the google icon. So the click is being fired. So maybe the problem is in the sharethis.com javascript.
    – slugolicious
    yesterday










  • that's a great observation. it might be in the library! but why would it work when clicked and work with the email, but not with the enter keypress? it kills me that it is working with the email and not with anything else, because I know my code is working but not on every single button.... thank you @slugolicious !!
    – cpick
    yesterday












  • I hadn't tried mouse clicking on them. Indeed, all of them work for me too. I added this to the "each" loop after the keypress() declaration so that all the elements had an onclick: $(this).click(function (e) { alert('my click'); });. Pressing ENTER on all the elements runs the "my click" but only the email pops up a dialog. One other difference is email opens a dialog within the same page whereas all the others open a new browser window (when you click with the mouse). So there is some consistency as to the images that don't work.
    – slugolicious
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using the ShareThis library for a site I am working on. I want to make this site accessible, so that a user can tab through and hit enter and trigger a click event. Right now, when a user hits enter on any of the social media buttons, a console message shows up but it doesn't treat it like a click and open the sharing page.



This is working on only the last button, the email button. It opens the right modal (every other button opens a different page) but each one still prints out the console message. Here is my code, I am unsure why it is not working.



Here is my JS code:



$('.sharethis-body .keypress-click').each(function () {
$(this).keypress(function (e) {
var key = e.which;
if (key == 13) // the enter key code
{
$(this).click();
console.log("click");
return false;
}
return true;
});
});


And here is my HTML:



    <div class="sharethis-body">
<div class="sthoverbuttons-label"><span>Share</span></div>
<span tabindex="0" class='st_facebook_large keypress-click' displaytext='Facebook' aria-label='Facebook'></span>
<span tabindex="0" class='st_twitter_large keypress-click' displaytext='Tweet' aria-label='Twitter'></span>
<span tabindex="0" class='st_googleplus_large keypress-click' displaytext='Google +' aria-label='Google Plus'></span>
<span tabindex="0" class='st_linkedin_large keypress-click' displaytext='LinkedIn' aria-label='LinkedIn'></span>
<span tabindex="0" class='st_email_large keypress-click' displaytext='Email' aria-label='Email'></span>
</div>


Any help with this would be greatly appreciated!










share|improve this question















I am using the ShareThis library for a site I am working on. I want to make this site accessible, so that a user can tab through and hit enter and trigger a click event. Right now, when a user hits enter on any of the social media buttons, a console message shows up but it doesn't treat it like a click and open the sharing page.



This is working on only the last button, the email button. It opens the right modal (every other button opens a different page) but each one still prints out the console message. Here is my code, I am unsure why it is not working.



Here is my JS code:



$('.sharethis-body .keypress-click').each(function () {
$(this).keypress(function (e) {
var key = e.which;
if (key == 13) // the enter key code
{
$(this).click();
console.log("click");
return false;
}
return true;
});
});


And here is my HTML:



    <div class="sharethis-body">
<div class="sthoverbuttons-label"><span>Share</span></div>
<span tabindex="0" class='st_facebook_large keypress-click' displaytext='Facebook' aria-label='Facebook'></span>
<span tabindex="0" class='st_twitter_large keypress-click' displaytext='Tweet' aria-label='Twitter'></span>
<span tabindex="0" class='st_googleplus_large keypress-click' displaytext='Google +' aria-label='Google Plus'></span>
<span tabindex="0" class='st_linkedin_large keypress-click' displaytext='LinkedIn' aria-label='LinkedIn'></span>
<span tabindex="0" class='st_email_large keypress-click' displaytext='Email' aria-label='Email'></span>
</div>


Any help with this would be greatly appreciated!







java html accessibility sharethis






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked yesterday









cpick

53




53












  • I tried your example in a simple test file with your JS code in my onload() and just the html you have above in addition to <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>. I get the same problem. Only email works. I tried changing the order of the spans (email in the middle) and still only email worked. I then added an onclick() handler to the google span and it runs when I press ENTER on the google icon. So the click is being fired. So maybe the problem is in the sharethis.com javascript.
    – slugolicious
    yesterday










  • that's a great observation. it might be in the library! but why would it work when clicked and work with the email, but not with the enter keypress? it kills me that it is working with the email and not with anything else, because I know my code is working but not on every single button.... thank you @slugolicious !!
    – cpick
    yesterday












  • I hadn't tried mouse clicking on them. Indeed, all of them work for me too. I added this to the "each" loop after the keypress() declaration so that all the elements had an onclick: $(this).click(function (e) { alert('my click'); });. Pressing ENTER on all the elements runs the "my click" but only the email pops up a dialog. One other difference is email opens a dialog within the same page whereas all the others open a new browser window (when you click with the mouse). So there is some consistency as to the images that don't work.
    – slugolicious
    yesterday


















  • I tried your example in a simple test file with your JS code in my onload() and just the html you have above in addition to <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>. I get the same problem. Only email works. I tried changing the order of the spans (email in the middle) and still only email worked. I then added an onclick() handler to the google span and it runs when I press ENTER on the google icon. So the click is being fired. So maybe the problem is in the sharethis.com javascript.
    – slugolicious
    yesterday










  • that's a great observation. it might be in the library! but why would it work when clicked and work with the email, but not with the enter keypress? it kills me that it is working with the email and not with anything else, because I know my code is working but not on every single button.... thank you @slugolicious !!
    – cpick
    yesterday












  • I hadn't tried mouse clicking on them. Indeed, all of them work for me too. I added this to the "each" loop after the keypress() declaration so that all the elements had an onclick: $(this).click(function (e) { alert('my click'); });. Pressing ENTER on all the elements runs the "my click" but only the email pops up a dialog. One other difference is email opens a dialog within the same page whereas all the others open a new browser window (when you click with the mouse). So there is some consistency as to the images that don't work.
    – slugolicious
    yesterday
















I tried your example in a simple test file with your JS code in my onload() and just the html you have above in addition to <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>. I get the same problem. Only email works. I tried changing the order of the spans (email in the middle) and still only email worked. I then added an onclick() handler to the google span and it runs when I press ENTER on the google icon. So the click is being fired. So maybe the problem is in the sharethis.com javascript.
– slugolicious
yesterday




I tried your example in a simple test file with your JS code in my onload() and just the html you have above in addition to <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>. I get the same problem. Only email works. I tried changing the order of the spans (email in the middle) and still only email worked. I then added an onclick() handler to the google span and it runs when I press ENTER on the google icon. So the click is being fired. So maybe the problem is in the sharethis.com javascript.
– slugolicious
yesterday












that's a great observation. it might be in the library! but why would it work when clicked and work with the email, but not with the enter keypress? it kills me that it is working with the email and not with anything else, because I know my code is working but not on every single button.... thank you @slugolicious !!
– cpick
yesterday






that's a great observation. it might be in the library! but why would it work when clicked and work with the email, but not with the enter keypress? it kills me that it is working with the email and not with anything else, because I know my code is working but not on every single button.... thank you @slugolicious !!
– cpick
yesterday














I hadn't tried mouse clicking on them. Indeed, all of them work for me too. I added this to the "each" loop after the keypress() declaration so that all the elements had an onclick: $(this).click(function (e) { alert('my click'); });. Pressing ENTER on all the elements runs the "my click" but only the email pops up a dialog. One other difference is email opens a dialog within the same page whereas all the others open a new browser window (when you click with the mouse). So there is some consistency as to the images that don't work.
– slugolicious
yesterday




I hadn't tried mouse clicking on them. Indeed, all of them work for me too. I added this to the "each" loop after the keypress() declaration so that all the elements had an onclick: $(this).click(function (e) { alert('my click'); });. Pressing ENTER on all the elements runs the "my click" but only the email pops up a dialog. One other difference is email opens a dialog within the same page whereas all the others open a new browser window (when you click with the mouse). So there is some consistency as to the images that don't work.
– slugolicious
yesterday












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Not knowing how ShareThis is used but your issue can be corrected by changing the "span" to "button". By using buttons, you gain the native focus ability. It's also possible for you to clean up your code to look something like this.



Facebook






share|improve this answer





















  • unfortunately, this does not change anything. this only adds a box around the icon to have it styled like a button, it does not change any behavior.
    – cpick
    yesterday











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343710%2fkeypress-wont-trigger-on-all-my-social-buttons-just-one%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Not knowing how ShareThis is used but your issue can be corrected by changing the "span" to "button". By using buttons, you gain the native focus ability. It's also possible for you to clean up your code to look something like this.



Facebook






share|improve this answer





















  • unfortunately, this does not change anything. this only adds a box around the icon to have it styled like a button, it does not change any behavior.
    – cpick
    yesterday















up vote
0
down vote













Not knowing how ShareThis is used but your issue can be corrected by changing the "span" to "button". By using buttons, you gain the native focus ability. It's also possible for you to clean up your code to look something like this.



Facebook






share|improve this answer





















  • unfortunately, this does not change anything. this only adds a box around the icon to have it styled like a button, it does not change any behavior.
    – cpick
    yesterday













up vote
0
down vote










up vote
0
down vote









Not knowing how ShareThis is used but your issue can be corrected by changing the "span" to "button". By using buttons, you gain the native focus ability. It's also possible for you to clean up your code to look something like this.



Facebook






share|improve this answer












Not knowing how ShareThis is used but your issue can be corrected by changing the "span" to "button". By using buttons, you gain the native focus ability. It's also possible for you to clean up your code to look something like this.



Facebook







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









xirclebox

212




212












  • unfortunately, this does not change anything. this only adds a box around the icon to have it styled like a button, it does not change any behavior.
    – cpick
    yesterday


















  • unfortunately, this does not change anything. this only adds a box around the icon to have it styled like a button, it does not change any behavior.
    – cpick
    yesterday
















unfortunately, this does not change anything. this only adds a box around the icon to have it styled like a button, it does not change any behavior.
– cpick
yesterday




unfortunately, this does not change anything. this only adds a box around the icon to have it styled like a button, it does not change any behavior.
– cpick
yesterday


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343710%2fkeypress-wont-trigger-on-all-my-social-buttons-just-one%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy