1

I have this code

var pathname = window.location.pathname;

That take the current browser url

How can i paste the pathname into an html element like a p tag?

1
  • Cool. What did you try and what happens? Commented Mar 30, 2012 at 18:06

1 Answer 1

7

Use this:

$('p.class').html(location.pathname);

If you want to get the full URL:

$('p.class').html(location.href);
Sign up to request clarification or add additional context in comments.

2 Comments

FYI -- If one wanted to get the URL rather than the PATH, one could use locaiton.href.
That's right, but if you just want the path name (for this page it'd be /questions/9948212/jquery-get-browser-url-and-insert-into-html-element), you'd use this

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.