I have 3 pages, the 2 pages are WordPress pages and the other 1 is a custom page template with a form. The 2 pages are created using wp-job manager plugin. The 1st page has had a dropdown menu and contains list of jobs. On the 2nd page is the description of a job.
Now, I want to get the value of h1 tag on the 2nd page after the user click the input button and pass it to the 3rd page and displayed it in one of the input textbox (Position input textbox) using JS.
How to do this?
Here’s the link of the 2nd page
3rd page
HTML:
<header class="entry-header">
<h1 class="entry-title">Collections Trainer</h1>
</header>
Vanilla JavaScript solution (no framework required):
can you use jquery? if so, get the h1 values when you click the button from jquery and then sent to the other page using query string.
EDITED
Add the jquery file in your page to user jquery features. And you need to put the function inside $(document).ready() function in order to attach the function into the object.
you can learn more about jquery in https://learn.jquery.com/.
Use the class you’ve given the heading in normal js use the following.
If you’re using jQuery then its
Hope that helps.
If you want to get the h1 value only after the button click you will need to put the onclick for the button.
PS:You need to also include the jquery source to your page.
jQuery: To get H1 value
As you need to fetch values on other pages, for that you can send values via QueryString or using HTML5 LocalStorage
Sample Code:
On third Page you can get both pages header text
If you are using Jquery then i would recommend that you give id to your H1 tag assuming id of your H1 tag is “h1Title”.
HTML:
Then to get the title you write following in JQuery:
By this you will get text of your heading.