Nabe
Nabe

Reputation: 95

Need to show id in href tag but not navigate into other page

I need to show item id in a href tag ,but it must not navigate into other page... one way to prevent navigation is using jvascriptvoid(0) but can i append it to id... If so how??

 <a href="id='.$portfolio_id.' "><img height="57" width="57" src="images/portfolio_uploads/orig_'.$portfolio_item['image'].'"></a>

Upvotes: 1

Views: 544

Answers (4)

Alexander
Alexander

Reputation: 23537

You shouldn't use an <a> tag in first place. You can always use another kind of tag to display information. Specially since the contents of your href attribute aren't really valid links. Using an id attribute in your enclosed <img> should be even better.

<img id="'.$portfolio_id.'">

Or adapting your layout would be a better approach.

Upvotes: 0

Curtis
Curtis

Reputation: 103348

Add onclick="return false;" to your anchor tag. This will prevent the link from being navigated to.

<a href="id='.$portfolio_id.' " onclick="return false;"><img height="57" width="57" src="images/portfolio_uploads/orig_'.$portfolio_item['image'].'" /></a>

However, I don't understand the point of this, and this isn't want the anchor tag is designed for. Perhaps if you supply more information we can find a better solution.

Upvotes: 2

Sivanath
Sivanath

Reputation: 559

Add "#" character in-front of the id, it wont navigate to other page.

<a href="#id='.$portfolio_id.' "><img height="57" width="57" src="images/portfolio_uploads/orig_'.$portfolio_item['image'].'" /></a>

Upvotes: 0

MrCode
MrCode

Reputation: 64526

Assign a click event and return false, this will stop the browser from navigating to the href.

<script type="text/javascript">

window.onload = function()
{

    document.getElementById("mylink").onclick = function()
    {
        return false;
    }

}

</script>


 <a id="mylink" href="http://google.com"><img height="57" width="57" src="images/portfolio_uploads/orig_'.$portfolio_item['image'].'"></a>

Upvotes: 0

Related Questions