Writing to a non-unique div with Javascript

I am creating an RSS reader for several feeds for school.

aList is a div that spans each individual channel (the number of feeds will fluctuate).

theTitle is a div that will be populated with the attribute of the current feed. In addition, if you click, it will load the list of attributes from the current feed into TheContent.

I am wondering how I can dynamically load attributes into TheContent when the Title button is pressed, since theContent and theTitle will not be unique divs (I cannot give them an ID).

Thanks for your help in advance,

-Andrew

+5
source share
6 answers

document.getElementsByClassName ('ALIST'). GetElementsByTagName ('DIV')

+1

jQuery DOM. -

$("div.theContent").attr("name", "value");
+1

jquery, :

 $(".theTitle").bind("click", function(){
    $el = $(this);
           $el.parent().$(".theContent").load('ajax/content.php?news=' . $el.text());
 });

, , div ajax/content.php? news = theTitle-value

+1
<div class="aList">
<div class="theTitle" onclick="fillContentBox(this)"></div>
<div class="theContent"></div>
</div>

script...

function fillContentBox(div) {
  var theContentDiv = div.parentNode.getElementsByTagName("div")[1];
  // statements that do things with theContentDiv
}
+1

Javascript, ​​ Prototype jQuery. , .

div :

$('div.theTitle')

jQuery :

$('div.theTitle').click( function() {
    var title = $(this).text();
    var contentDiv = $(this).siblings('div.theContent');
    // Do something with contentDiv and the title
} );

This will cause each div div to have an onClick event that does something with its associated div.

+1
source

You should be able to determine which item you want to update if you do not want to update more than one. If elements are grouped inside something else that has an id value, you can take advantage of this.

0
source

All Articles