Because of the nature of what im trying to do, the ids of the divs im creating are all from a foreach loop array but the div is classed so when i click an onsubmit i need to find all the IDs for a particular className and put them all into an array.
How can i do this.
[php]
foreach($sections as $section)
{
$parts = explode('{', $section);
$selector = trim($parts[0]);
$elements = explode(';', $parts[1]);
// below is the div im on about
echo "\n\n<br><div class=\"selector\" id=\"$selector\">".$selector."</div><br>\n\n";
[/php]
Above is the what i have done to create the divs.
8 3807
Because of the nature of what im trying to do, the ids of the divs im creating are all from a foreach loop array but the div is classed so when i click an onsubmit i need to find all the IDs for a particular className and put them all into an array.
How can i do this.
[php]
foreach($sections as $section)
{
$parts = explode('{', $section);
$selector = trim($parts[0]);
$elements = explode(';', $parts[1]);
// below is the div im on about
echo "\n\n<br><div class=\"selector\" id=\"$selector\">".$selector."</div><br>\n\n";
[/php]
Above is the what i have done to create the divs.
Is this a PHP question or Javascript?
This is a javascript question, im just demonstrating how i have created the divs and how each id from the div is differernt, but the className is always the same.
I want to find all the ID names from a parictular className in javascript. For example:
<div class="test" id="hello"></div>
<div class="test" id="anotherID"></div>
<div class="test" id="getTheIdea"></div>
<div class="test" id="IDisDifferentfromClassName"></div>
So i want to do a:
var getID=document.getElementByClassName('test');
var something="find all the ids from the className 'test';
var arrayID=" get all the IDS and put them into an array"
DO you see what i want to do?
There are many implementations of getElementsByClassName, e.g. Dustin Diaz Robert Nyman
Then get the ids of these objects by looping through them.
Is there anything wrong with this: -
function getElements()
-
{
-
var x=document.getElementsByClassName("selector");
-
alert(x.length);
-
}
-
it works if i use getElementsByName? Also does mozilla support getElementsByClassName?
-
divs = document.getElementsByTagName("div");
-
idArray = new Array();
-
-
for (x=0; x<divs.length; x++) {
-
if (divs[x].className=="classe") {
-
idArray[x] = divs[x].id
-
}
-
}
-
classe is my test class
divs my variable to hold the tags divs
idarray my test array
Is there anything wrong with this: -
function getElements()
-
{
-
var x=document.getElementsByClassName("selector");
-
alert(x.length);
-
}
-
it works if i use getElementsByName? Also does mozilla support getElementsByClassName?
getElementsByClassName is a function, not a method of document. I don't think it is supported. It may be supported in later releases of browsers. That's why you have to write your own.
-
divs = document.getElementsByTagName("div");
-
idArray = new Array();
-
-
for (x=0; x<divs.length; x++) {
-
if (divs[x].className=="classe") {
-
idArray[x] = divs[x].id
-
}
-
}
-
classe is my test class
divs my variable to hold the tags divs
idarray my test array
Good solution and will probably be sufficient in this situation, but it doesn't take into account multiple classes, e.g. - <div class="class1 class2" id="...">
There are many implementations of getElementsByClassName, e.g. Dustin Diaz Robert Nyman
Then get the ids of these objects by looping through them.
You are right! And here's another one: xGetElementsByClassName(sClsName, oParentEle, sTagName, fnCallback).
It can be used in two different ways:
(1) Iterate through the returned array: -
var i, a = xGetElementsByClassName(sClsName, oParentEle, sTagName);
-
for (i = 0; i < a.length; ++i) {
-
// a[i] is an element with sClsName as one of its class names
-
}
-
(2) Provide a callback function: -
xGetElementsByClassName(sClsName, oParentEle, sTagName,
-
function(ele) {
-
// ele is an element with sClsName as one of its class names
-
}
-
);
-
:)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joshua Beall |
last post by:
Hi All,
I have been trying to dynamically call a static member function, as follows:
$className = 'MyClass';
$methodName = 'MyMethod'
$result = $className::$methodName();
However, I get a...
|
by: Peter King |
last post by:
if you assign multiple classes in order to keep your classes generic
e.g
..classA { position.absolute; left:5 top:5 height:200 width:800 }
..classB { background-color: red}
..classC {...
|
by: Ben R. |
last post by:
Between ClassName and Inherits, which attribute is set to specify the class
that a page uses? I would think that would be inherits. Further, the
description for ClassName is:
Specifies the class...
|
by: Sri |
last post by:
I am writing an asp.net applicaition using VB coding.
In a function, I am opening an excel file with the following code,
Dim objExcel As Object
Dim objWorkBook As Object
objExcel =...
|
by: enahar |
last post by:
Hello,
i want to find out how many instances of a form (say childForm1) is
running using FindWindowEx but value return is always zero by this method.
What wrong I am doing it..Can anybody...
|
by: bmgz |
last post by:
I have written a script that highlights a table row when the appropriate
checkbox is checked. Using element.style is a bit messy and doesn't
really fulfil my needs..
I want to just be able to...
|
by: arne |
last post by:
Hi
what would be the easiest way to find all tag's with a certain name (or
class) below (within) a certain tag.
Pref jscript DOM
thx
Arne
|
by: Jacob Avlund |
last post by:
Hello all,
I wish to load two user controls (cart.ascx and products.ascx)
programatically.
What I'm doing right now:
In my aspx file, two references are added:
<%@ Reference...
|
by: benjamin |
last post by:
I'm new at JS and DOM, so please bear with me... Here's what I'm trying
to do:
My code is such as this:
***
<div class="post" id="123">
lorem ipsum
<div class="tag1">hello</div>
</div>
|
by: laredotornado |
last post by:
Hi,
Please let me know if there is a better place to which to post this
message. I'm trying to use prototype.js and wondering how I use it to
find elements on page with class = "myClass"?
...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |