JavaScript How to get the value of h1 tag using JS? value using vin,value using cap rate,@value using,value

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>
Answer:1

Vanilla JavaScript solution (no framework required):

var h1Text = document.querySelector(".entry-title").textContent;
Answer:2

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/.

<script src="https://code.jquery.com/jquery-2.2.0.min.js"/>
<script>
  $(document).ready(function(){
   $('.application_button').click(function(){
        var headervalue = $(".entry-title").text();
        window.location = "http://homecredit.ph/testEnvironment/4537-2/?position="+headervalue;
    });
});
</script>
Answer:3

Use the class you've given the heading in normal js use the following.

var x = document.getElementsByClassName('entry-title').value;
console.log(x); //outputs collections trainer

If you're using jQuery then its

$('.entry-title').text

Hope that helps.

Answer:4

If you want to get the h1 value only after the button click you will need to put the onclick for the button.

$.(document).ready(function(){
var header1Text ='';
 $('.application_button').onclick(function(){
   header1Text = $('h1').html();
  });
//To display it in whichever textbox you want:
$('#GivesomeIDtoYourTextBox').val(header1Text);
});

PS:You need to also include the jquery source to your page.

Answer:5

jQuery: To get H1 value

 var gValue=jQuery("header h1.entry-title").text();
    alert(gValue);

As you need to fetch values on other pages, for that you can send values via QueryString or using HTML5 LocalStorage Sample Code:

var first_page_h1_Value=jQuery("header h1.entry-title").text();
var second_page_h1_Value=jQuery("header h1.entry-title").text();

localStorage.setItem("FirstPage", first_page_h1_Value);
localStorage.setItem("SecondPage", second_page_h1_Value);

On third Page you can get both pages header text

 alert(localStorage.FirstPage);
 alert(localStorage.SecondPage);
Answer:6

I am trying to replicate the functionality of Google's Cardboard Demo "Exhibit" with three.js. I took the starting example straight from the Chrome Experiments web page and just dropped in code to ...

I am trying to replicate the functionality of Google's Cardboard Demo "Exhibit" with three.js. I took the starting example straight from the Chrome Experiments web page and just dropped in code to ...

I'm using AngularJS to prefetch images in cache client and then I want to animate those prefetched images. My code for the prefetching: $scope.prefetch=function(limit) { for (var i=0; i<limit; ...

I'm using AngularJS to prefetch images in cache client and then I want to animate those prefetched images. My code for the prefetching: $scope.prefetch=function(limit) { for (var i=0; i<limit; ...

  1. jquery play sequence images
  2. matlab play sequence of images
  3. javascript play sequence of images

I have a div table and would like to get the id value of the class live-mu-table-tdq that is to the left of where I click. I thought that the following code would work but it didn't. $(this).closest(...

I have a div table and would like to get the id value of the class live-mu-table-tdq that is to the left of where I click. I thought that the following code would work but it didn't. $(this).closest(...

Is it possible to create dynamic templates/pages with TVML without relying on Apple's standard templates? Say I'd like to create a template that has 2 images next to each other and on top of these ...

Is it possible to create dynamic templates/pages with TVML without relying on Apple's standard templates? Say I'd like to create a template that has 2 images next to each other and on top of these ...