0

That's what I have: <a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a>. <?=$arItem["LINK"]?> - it's an array, which contains some links. I need to add an extra hashtag parameter #nav-link to the end of each link. That's how I tried do it, but this code doesn't work:

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

I don't know PHP quite well, but I think I need to add new array and return there all necessary links with hashtag and use this array in href.

Thanks for help!

6
  • 1
    Note sure it helps but I think it should be $("#likeLink").attr("href", "<?=$arItem["LINK"]?>#nav-link"); Commented Oct 2, 2014 at 20:19
  • Is this code in a loop in php? Commented Oct 2, 2014 at 20:21
  • @nicolas Unfortunately the result is the same, after second click I get only last element of the array Commented Oct 2, 2014 at 20:25
  • @Sean Yes, but it works well in this variant <a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a> Commented Oct 2, 2014 at 20:26
  • 2
    It sounds like you might have an id issue. ids are supposed to be UNIQUE, so if this is in a loop you will have n number of id="likeLink". jQuery/javascript will not know which $("#likeLink") you are linking to. Commented Oct 2, 2014 at 20:32

2 Answers 2

1

You have to give your php to javascript into a javascript string:

$("#likeLink").attr("href", "<?=$arItem["LINK"]?>#nav-link");

Sign up to request clarification or add additional context in comments.

Comments

0

It's hard to say without knowing more but it looks like you need quotes around the link on this line:

$("#likeLink").attr("href", "<?=$arItem["LINK"]?>" + "#nav-link");

4 Comments

Unfortunately the result is the same, after second click I get only last element of the array
Does it work if you just put the code in PHP? $("#likeLink").attr("href", "<?php echo $arItem["LINK"].'#nav-link'; ?>");
There's no reason it would be any different. I'm just curious if there's some code we can't see that's causing the issue.
I'm sure there are guys here hefty enough to fix bugs in code that they can't see :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.