Php: How to link a URL with ID targeting a html section?

Muhammad Ahmed picture Muhammad Ahmed · Oct 3, 2013 · Viewed 14.6k times · Source

New to php :)

Working on a blog project, I want to navigate (send) the users to another page with specific (complete) post and its comments by clicking "Comments" link on index page.

I wish to send the user directly to the comments div. but I also have to provide post ID with the link after question mark"?". I want to know where to include #comments div (html section) in the url.

Thank you in advance.

Answer

Chokchai picture Chokchai · Oct 3, 2013

First, assign the id to the element you want browser (user) scroll to.

Ex.

<div id="mycomment">

Then, generate the url that append with # and id you choose.

Ex.

http://example.com/post/1/#mycomment