How to create a click event on li rel










-2















I have a list its have been created by an java script from the select object.



But i cant create an click event on this lists on rel urls



<ul class="select-options">

<li rel="category/flowers.html?show=12">12</li>
<li rel="category/flowers.html?show=24">24</li>
<li rel="category/flowers.html?show=36">36</li>

</ul>


My list is showing like this.



My main mission is when an user click on the list ; js will get url from the rel and redirect to that url.










share|improve this question

















  • 1





    Use <a href="category/flowers.html?show=12">12</a> for the task. Why would you rebuild links in a non-semantic way which even requires JS and thus, doesn't degrade gracefully? This is bad practice in almost all the ways I can think of.

    – connexo
    Nov 15 '18 at 18:10











  • I know how to create links. But That template i have started to editing, works like this. I cant change js files because of it required other pages. But now my problem is fixed by Jayesh Goyani's answer.

    – Emre Y
    Nov 15 '18 at 18:13






  • 1





    Then I'd highly recommend to fix that template.

    – connexo
    Nov 15 '18 at 18:13












  • please check your skype.

    – Emre Y
    Nov 15 '18 at 18:17















-2















I have a list its have been created by an java script from the select object.



But i cant create an click event on this lists on rel urls



<ul class="select-options">

<li rel="category/flowers.html?show=12">12</li>
<li rel="category/flowers.html?show=24">24</li>
<li rel="category/flowers.html?show=36">36</li>

</ul>


My list is showing like this.



My main mission is when an user click on the list ; js will get url from the rel and redirect to that url.










share|improve this question

















  • 1





    Use <a href="category/flowers.html?show=12">12</a> for the task. Why would you rebuild links in a non-semantic way which even requires JS and thus, doesn't degrade gracefully? This is bad practice in almost all the ways I can think of.

    – connexo
    Nov 15 '18 at 18:10











  • I know how to create links. But That template i have started to editing, works like this. I cant change js files because of it required other pages. But now my problem is fixed by Jayesh Goyani's answer.

    – Emre Y
    Nov 15 '18 at 18:13






  • 1





    Then I'd highly recommend to fix that template.

    – connexo
    Nov 15 '18 at 18:13












  • please check your skype.

    – Emre Y
    Nov 15 '18 at 18:17













-2












-2








-2








I have a list its have been created by an java script from the select object.



But i cant create an click event on this lists on rel urls



<ul class="select-options">

<li rel="category/flowers.html?show=12">12</li>
<li rel="category/flowers.html?show=24">24</li>
<li rel="category/flowers.html?show=36">36</li>

</ul>


My list is showing like this.



My main mission is when an user click on the list ; js will get url from the rel and redirect to that url.










share|improve this question














I have a list its have been created by an java script from the select object.



But i cant create an click event on this lists on rel urls



<ul class="select-options">

<li rel="category/flowers.html?show=12">12</li>
<li rel="category/flowers.html?show=24">24</li>
<li rel="category/flowers.html?show=36">36</li>

</ul>


My list is showing like this.



My main mission is when an user click on the list ; js will get url from the rel and redirect to that url.







javascript jquery html






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 17:27









Emre YEmre Y

121111




121111







  • 1





    Use <a href="category/flowers.html?show=12">12</a> for the task. Why would you rebuild links in a non-semantic way which even requires JS and thus, doesn't degrade gracefully? This is bad practice in almost all the ways I can think of.

    – connexo
    Nov 15 '18 at 18:10











  • I know how to create links. But That template i have started to editing, works like this. I cant change js files because of it required other pages. But now my problem is fixed by Jayesh Goyani's answer.

    – Emre Y
    Nov 15 '18 at 18:13






  • 1





    Then I'd highly recommend to fix that template.

    – connexo
    Nov 15 '18 at 18:13












  • please check your skype.

    – Emre Y
    Nov 15 '18 at 18:17












  • 1





    Use <a href="category/flowers.html?show=12">12</a> for the task. Why would you rebuild links in a non-semantic way which even requires JS and thus, doesn't degrade gracefully? This is bad practice in almost all the ways I can think of.

    – connexo
    Nov 15 '18 at 18:10











  • I know how to create links. But That template i have started to editing, works like this. I cant change js files because of it required other pages. But now my problem is fixed by Jayesh Goyani's answer.

    – Emre Y
    Nov 15 '18 at 18:13






  • 1





    Then I'd highly recommend to fix that template.

    – connexo
    Nov 15 '18 at 18:13












  • please check your skype.

    – Emre Y
    Nov 15 '18 at 18:17







1




1





Use <a href="category/flowers.html?show=12">12</a> for the task. Why would you rebuild links in a non-semantic way which even requires JS and thus, doesn't degrade gracefully? This is bad practice in almost all the ways I can think of.

– connexo
Nov 15 '18 at 18:10





Use <a href="category/flowers.html?show=12">12</a> for the task. Why would you rebuild links in a non-semantic way which even requires JS and thus, doesn't degrade gracefully? This is bad practice in almost all the ways I can think of.

– connexo
Nov 15 '18 at 18:10













I know how to create links. But That template i have started to editing, works like this. I cant change js files because of it required other pages. But now my problem is fixed by Jayesh Goyani's answer.

– Emre Y
Nov 15 '18 at 18:13





I know how to create links. But That template i have started to editing, works like this. I cant change js files because of it required other pages. But now my problem is fixed by Jayesh Goyani's answer.

– Emre Y
Nov 15 '18 at 18:13




1




1





Then I'd highly recommend to fix that template.

– connexo
Nov 15 '18 at 18:13






Then I'd highly recommend to fix that template.

– connexo
Nov 15 '18 at 18:13














please check your skype.

– Emre Y
Nov 15 '18 at 18:17





please check your skype.

– Emre Y
Nov 15 '18 at 18:17












2 Answers
2






active

oldest

votes


















-1














Please try with the below code snippet.



Method 1:-



$('.select-options li').click(function()
var rel = $(this).attr('rel');
window.location.href = rel;
);


Method 2:-



<ul class="select-options">

<li rel="category/flowers.html?show=12" onclick="redirectPage(this)">12</li>
<li rel="category/flowers.html?show=24" onclick="redirectPage(this)">24</li>
<li rel="category/flowers.html?show=36" onclick="redirectPage(this)">36</li>

</ul>
.......
.......
function redirectPage(obj)


var rel = $(obj).prop('rel');
window.location.href = rel;



Method 3:-



$( document ).ready(function() 


$('.select-options li').on( "click", function( event )
var rel =$(this).attr('rel');
window.location.href = rel;
);

);





share|improve this answer

























  • It logs the console this error ; Uncaught ReferenceError: $ is not defined

    – Emre Y
    Nov 15 '18 at 17:35






  • 2





    have you added jquery reference in your page?

    – Jayesh Goyani
    Nov 15 '18 at 17:36











  • Yes but that was placed before your code. Now i think it cant find the li element with the select-options class. Because the select-options class is ul's class

    – Emre Y
    Nov 15 '18 at 17:39






  • 1





    any luck with method 3?

    – Jayesh Goyani
    Nov 15 '18 at 17:51







  • 1





    Method 3 worked with attr :) You made my day thank you so much. I'm new at the javascript, day by day im learning new thing. Have a nice day.

    – Emre Y
    Nov 15 '18 at 18:04


















-1














The rel attribute in your li tag specifies the relation between the current document and the linked document.
You should use the href attribute to redirect.



<li href="http://your-link-here">Click Here</li>






share|improve this answer

























  • Yeah, i know but that template producing my list from the <select> to <ul> and getting the value of select into rel

    – Emre Y
    Nov 15 '18 at 17:36











  • Please read my question right and careful.

    – Emre Y
    Nov 15 '18 at 17:58











  • href is an invalid attribute on li.

    – connexo
    Nov 15 '18 at 18:12










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',
autoActivateHeartbeat: false,
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%2f53324921%2fhow-to-create-a-click-event-on-li-rel%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














Please try with the below code snippet.



Method 1:-



$('.select-options li').click(function()
var rel = $(this).attr('rel');
window.location.href = rel;
);


Method 2:-



<ul class="select-options">

<li rel="category/flowers.html?show=12" onclick="redirectPage(this)">12</li>
<li rel="category/flowers.html?show=24" onclick="redirectPage(this)">24</li>
<li rel="category/flowers.html?show=36" onclick="redirectPage(this)">36</li>

</ul>
.......
.......
function redirectPage(obj)


var rel = $(obj).prop('rel');
window.location.href = rel;



Method 3:-



$( document ).ready(function() 


$('.select-options li').on( "click", function( event )
var rel =$(this).attr('rel');
window.location.href = rel;
);

);





share|improve this answer

























  • It logs the console this error ; Uncaught ReferenceError: $ is not defined

    – Emre Y
    Nov 15 '18 at 17:35






  • 2





    have you added jquery reference in your page?

    – Jayesh Goyani
    Nov 15 '18 at 17:36











  • Yes but that was placed before your code. Now i think it cant find the li element with the select-options class. Because the select-options class is ul's class

    – Emre Y
    Nov 15 '18 at 17:39






  • 1





    any luck with method 3?

    – Jayesh Goyani
    Nov 15 '18 at 17:51







  • 1





    Method 3 worked with attr :) You made my day thank you so much. I'm new at the javascript, day by day im learning new thing. Have a nice day.

    – Emre Y
    Nov 15 '18 at 18:04















-1














Please try with the below code snippet.



Method 1:-



$('.select-options li').click(function()
var rel = $(this).attr('rel');
window.location.href = rel;
);


Method 2:-



<ul class="select-options">

<li rel="category/flowers.html?show=12" onclick="redirectPage(this)">12</li>
<li rel="category/flowers.html?show=24" onclick="redirectPage(this)">24</li>
<li rel="category/flowers.html?show=36" onclick="redirectPage(this)">36</li>

</ul>
.......
.......
function redirectPage(obj)


var rel = $(obj).prop('rel');
window.location.href = rel;



Method 3:-



$( document ).ready(function() 


$('.select-options li').on( "click", function( event )
var rel =$(this).attr('rel');
window.location.href = rel;
);

);





share|improve this answer

























  • It logs the console this error ; Uncaught ReferenceError: $ is not defined

    – Emre Y
    Nov 15 '18 at 17:35






  • 2





    have you added jquery reference in your page?

    – Jayesh Goyani
    Nov 15 '18 at 17:36











  • Yes but that was placed before your code. Now i think it cant find the li element with the select-options class. Because the select-options class is ul's class

    – Emre Y
    Nov 15 '18 at 17:39






  • 1





    any luck with method 3?

    – Jayesh Goyani
    Nov 15 '18 at 17:51







  • 1





    Method 3 worked with attr :) You made my day thank you so much. I'm new at the javascript, day by day im learning new thing. Have a nice day.

    – Emre Y
    Nov 15 '18 at 18:04













-1












-1








-1







Please try with the below code snippet.



Method 1:-



$('.select-options li').click(function()
var rel = $(this).attr('rel');
window.location.href = rel;
);


Method 2:-



<ul class="select-options">

<li rel="category/flowers.html?show=12" onclick="redirectPage(this)">12</li>
<li rel="category/flowers.html?show=24" onclick="redirectPage(this)">24</li>
<li rel="category/flowers.html?show=36" onclick="redirectPage(this)">36</li>

</ul>
.......
.......
function redirectPage(obj)


var rel = $(obj).prop('rel');
window.location.href = rel;



Method 3:-



$( document ).ready(function() 


$('.select-options li').on( "click", function( event )
var rel =$(this).attr('rel');
window.location.href = rel;
);

);





share|improve this answer















Please try with the below code snippet.



Method 1:-



$('.select-options li').click(function()
var rel = $(this).attr('rel');
window.location.href = rel;
);


Method 2:-



<ul class="select-options">

<li rel="category/flowers.html?show=12" onclick="redirectPage(this)">12</li>
<li rel="category/flowers.html?show=24" onclick="redirectPage(this)">24</li>
<li rel="category/flowers.html?show=36" onclick="redirectPage(this)">36</li>

</ul>
.......
.......
function redirectPage(obj)


var rel = $(obj).prop('rel');
window.location.href = rel;



Method 3:-



$( document ).ready(function() 


$('.select-options li').on( "click", function( event )
var rel =$(this).attr('rel');
window.location.href = rel;
);

);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 17:59

























answered Nov 15 '18 at 17:30









Jayesh GoyaniJayesh Goyani

9,29141942




9,29141942












  • It logs the console this error ; Uncaught ReferenceError: $ is not defined

    – Emre Y
    Nov 15 '18 at 17:35






  • 2





    have you added jquery reference in your page?

    – Jayesh Goyani
    Nov 15 '18 at 17:36











  • Yes but that was placed before your code. Now i think it cant find the li element with the select-options class. Because the select-options class is ul's class

    – Emre Y
    Nov 15 '18 at 17:39






  • 1





    any luck with method 3?

    – Jayesh Goyani
    Nov 15 '18 at 17:51







  • 1





    Method 3 worked with attr :) You made my day thank you so much. I'm new at the javascript, day by day im learning new thing. Have a nice day.

    – Emre Y
    Nov 15 '18 at 18:04

















  • It logs the console this error ; Uncaught ReferenceError: $ is not defined

    – Emre Y
    Nov 15 '18 at 17:35






  • 2





    have you added jquery reference in your page?

    – Jayesh Goyani
    Nov 15 '18 at 17:36











  • Yes but that was placed before your code. Now i think it cant find the li element with the select-options class. Because the select-options class is ul's class

    – Emre Y
    Nov 15 '18 at 17:39






  • 1





    any luck with method 3?

    – Jayesh Goyani
    Nov 15 '18 at 17:51







  • 1





    Method 3 worked with attr :) You made my day thank you so much. I'm new at the javascript, day by day im learning new thing. Have a nice day.

    – Emre Y
    Nov 15 '18 at 18:04
















It logs the console this error ; Uncaught ReferenceError: $ is not defined

– Emre Y
Nov 15 '18 at 17:35





It logs the console this error ; Uncaught ReferenceError: $ is not defined

– Emre Y
Nov 15 '18 at 17:35




2




2





have you added jquery reference in your page?

– Jayesh Goyani
Nov 15 '18 at 17:36





have you added jquery reference in your page?

– Jayesh Goyani
Nov 15 '18 at 17:36













Yes but that was placed before your code. Now i think it cant find the li element with the select-options class. Because the select-options class is ul's class

– Emre Y
Nov 15 '18 at 17:39





Yes but that was placed before your code. Now i think it cant find the li element with the select-options class. Because the select-options class is ul's class

– Emre Y
Nov 15 '18 at 17:39




1




1





any luck with method 3?

– Jayesh Goyani
Nov 15 '18 at 17:51






any luck with method 3?

– Jayesh Goyani
Nov 15 '18 at 17:51





1




1





Method 3 worked with attr :) You made my day thank you so much. I'm new at the javascript, day by day im learning new thing. Have a nice day.

– Emre Y
Nov 15 '18 at 18:04





Method 3 worked with attr :) You made my day thank you so much. I'm new at the javascript, day by day im learning new thing. Have a nice day.

– Emre Y
Nov 15 '18 at 18:04













-1














The rel attribute in your li tag specifies the relation between the current document and the linked document.
You should use the href attribute to redirect.



<li href="http://your-link-here">Click Here</li>






share|improve this answer

























  • Yeah, i know but that template producing my list from the <select> to <ul> and getting the value of select into rel

    – Emre Y
    Nov 15 '18 at 17:36











  • Please read my question right and careful.

    – Emre Y
    Nov 15 '18 at 17:58











  • href is an invalid attribute on li.

    – connexo
    Nov 15 '18 at 18:12















-1














The rel attribute in your li tag specifies the relation between the current document and the linked document.
You should use the href attribute to redirect.



<li href="http://your-link-here">Click Here</li>






share|improve this answer

























  • Yeah, i know but that template producing my list from the <select> to <ul> and getting the value of select into rel

    – Emre Y
    Nov 15 '18 at 17:36











  • Please read my question right and careful.

    – Emre Y
    Nov 15 '18 at 17:58











  • href is an invalid attribute on li.

    – connexo
    Nov 15 '18 at 18:12













-1












-1








-1







The rel attribute in your li tag specifies the relation between the current document and the linked document.
You should use the href attribute to redirect.



<li href="http://your-link-here">Click Here</li>






share|improve this answer















The rel attribute in your li tag specifies the relation between the current document and the linked document.
You should use the href attribute to redirect.



<li href="http://your-link-here">Click Here</li>







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 17:36

























answered Nov 15 '18 at 17:33









Stefano AlvaresStefano Alvares

12




12












  • Yeah, i know but that template producing my list from the <select> to <ul> and getting the value of select into rel

    – Emre Y
    Nov 15 '18 at 17:36











  • Please read my question right and careful.

    – Emre Y
    Nov 15 '18 at 17:58











  • href is an invalid attribute on li.

    – connexo
    Nov 15 '18 at 18:12

















  • Yeah, i know but that template producing my list from the <select> to <ul> and getting the value of select into rel

    – Emre Y
    Nov 15 '18 at 17:36











  • Please read my question right and careful.

    – Emre Y
    Nov 15 '18 at 17:58











  • href is an invalid attribute on li.

    – connexo
    Nov 15 '18 at 18:12
















Yeah, i know but that template producing my list from the <select> to <ul> and getting the value of select into rel

– Emre Y
Nov 15 '18 at 17:36





Yeah, i know but that template producing my list from the <select> to <ul> and getting the value of select into rel

– Emre Y
Nov 15 '18 at 17:36













Please read my question right and careful.

– Emre Y
Nov 15 '18 at 17:58





Please read my question right and careful.

– Emre Y
Nov 15 '18 at 17:58













href is an invalid attribute on li.

– connexo
Nov 15 '18 at 18:12





href is an invalid attribute on li.

– connexo
Nov 15 '18 at 18:12

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53324921%2fhow-to-create-a-click-event-on-li-rel%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

27

Top Tejano songwriter Luis Silva dead of heart attack at 64

Category:Rhetoric