-3

How can i read only the data from the div element with id="title" using jquery?

  <div class="container-fluid" id="networdapp">
 <div class="row" >
    <div v-for="result in results" class="col-sm-6" >
      <div class="card m-3 h-240  bg-light">
         <div class="card-header text-center" id="title"> {{ result.title }} </div>
           <div class="card-body" style="height:200px" >
             <p class="card-text" v-html="result.prevDesc"></p>
           </div>
             <div class="card-footer bg-transparent border-info">
               <a href="/details" class="btn btn-info">Details</a>
             </div>
         </div>
      </div>
  </div>

j08691
  • 204,283
  • 31
  • 260
  • 272
DIIMIIM
  • 557
  • 7
  • 28
  • 1
    `$('#title').text()` you mean? – Mark Baijens Sep 06 '18 at 19:59
  • No,I meant how do i get the data from the div with title id passing through all the divs like $('#netowrdapp.row. ....') i mean..reading that data by accessing all the divs until i get to the title id.A similar concept would be the CSS commands like ul > li > a (passing through ul,then li and then a) – DIIMIIM Sep 06 '18 at 20:03
  • 1
    huh? what's wrong with `$('#title')`? – marzelin Sep 06 '18 at 20:07
  • That {{ result.title }} is data provided by a database and all this div is multiplying depending on how many records do i get from the database.If i use $('#title') i get only the title of the first record. – DIIMIIM Sep 06 '18 at 20:09
  • 3
    Yeah id's need to be unique. It's against the html standard to use the same id twice. Use a class selector for multiple elements. – Mark Baijens Sep 06 '18 at 20:10
  • 2
    id should only refer to a single element in the document – marzelin Sep 06 '18 at 20:10
  • then...how the JQuery command would show if i remove that id="title" and use only the classes of the divs?can you tell me please?The deadline is near... >_ – DIIMIIM Sep 06 '18 at 20:12
  • can you change `id="title"` to `class="title"`, or is it automatically rendered code from somewhere else? – marzelin Sep 06 '18 at 20:13
  • `$('.card-header')` gets all the div's with that class. – Mark Baijens Sep 06 '18 at 20:13
  • 2
    Your deadline isn't a concern of ours. You've also failed to show us what you've tried. – j08691 Sep 06 '18 at 20:14
  • 1
    You **cannot** have multiple elements with the same `id` value. Your HTML is invalid and **must** be fixed. – connexo Sep 06 '18 at 20:15

1 Answers1

0

you can't have more than one html element with the same id. Therefor, your doing a v-for which it means you have several times the same div with the id title. You may want to use a class instead of using a id in your div, with something like that :

<div class="title"></div>

And in jquery :

var div = $('.title')

If you have several div with the class title then the var div will be an array.