Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
159
rated 0 times [  163] [ 4]  / answers: 1 / hits: 64657  / 10 Years ago, sun, october 5, 2014, 12:00:00

Here's what I have:



<a href=<?=$arItem[LINK]?>><?=$arItem[TEXT]?></a>


It's a PHP array, which contains some links. I need to add an extra hash parameter #nav-link to the end of each link.



Here's how I tried do it:



<a id=likeLink href=><?=$arItem[TEXT]?></a>
<script>
$(document).ready(function () {
$(#likeLink).attr(href, <?=$arItem[LINK]?> + #nav-link);
});
</script>


But this code doesn't work because jQuery will not know which links I am linking to. So I guess that I need to generate the unique ids, but don't know how to do it.


More From » php

 Answers
36

For generating random ids you could use this one.



<script type=text/javascript>
function Generator() {};

Generator.prototype.rand = Math.floor(Math.random() * 26) + Date.now();

Generator.prototype.getId = function() {
return this.rand++;
};
var idGen =new Generator();
</script>
</html>
<body>
<!-- Place this in the body of the page content -->

<button onclick=console.log(idGen.getId())>click</button>

</body>

[#69239] Thursday, October 2, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryderalfonsos

Total Points: 655
Total Questions: 88
Total Answers: 91

Location: Nauru
Member since Thu, Feb 2, 2023
1 Year ago
ryderalfonsos questions
Mon, Sep 9, 19, 00:00, 5 Years ago
Wed, Feb 13, 19, 00:00, 5 Years ago
Tue, Feb 12, 19, 00:00, 5 Years ago
Fri, Dec 28, 18, 00:00, 6 Years ago
;