0

I would like to make a contents page on the fly,

Can i target a h1 tag on say page 001.html & 002.html and display it on contents.html using jquery?

Ma9ic
  • 1,107
  • 4
  • 16
  • 30

2 Answers2

3

Yes.

$('#result').load('001.html h1');

Where the h1 is a selector that will select your heading.

Matt Cain
  • 5,638
  • 3
  • 36
  • 45
2

contents.html

<div id="target"></div>

<script src=//jquery.min.js"></script>
<script type="text/javascript">
  $.get('001.html', function(html){
    $('#target').text($('h1',html).text());
  });
</script>

Where #target is an element with the id target within the contents page, and h1 is a selector that locates the <h1> you're after on the 001.html page.

Brad Christie
  • 100,477
  • 16
  • 156
  • 200