/    Sign up×
Community /Pin to ProfileBookmark

How to count the number of times a div appears?

Hi
I have created a script that checks through fields in a cmc and finds any opening and closing divs. What i want to do it count the number of times the opening/closing div appears in a field. any ideas?

[code]
ISite[] oSites = ms.getAvailableSites( ctx );

IType[] oSiteTypes = oSites[0].getTypes();

String[] aFields = null;

IItem[] oItemTest = null;

String sTarget = “<div”;
String sTarget2 = “</div>”;
String sFieldValue = “”;
String sField= “”;

int iCount = 0;
int iFullCount = 0;

for ( int k = 0; k < 10; k++ ){
out.print(“<h3>” + oSiteTypes[k].getName() + “</h3>”);

oItemTest = oSiteTypes[k].getAllItems();

for ( int j = 0; j < oItemTest.length; j++ )

{

aFields = oItemTest[j].getFieldNames();

for (int i = 0; i < aFields.length; i++ )
{

sFieldValue = oItemTest[j].getStringFieldValue( aFields[i] );

if ( sFieldValue != null)
{
if ( sFieldValue.indexOf( sTarget,0 ) >=0 )
{

try {

iCount ++;
out.print( j + “Opening: ” + oItemTest[j].getPath() + “,” + oItemTest[j].getFullName() + “,” + aFields[i] + “n” + “<br>”);

}
catch ( Exception e ) {out.print(“no”); }

}
if ( sFieldValue.indexOf( sTarget2,0 ) >=0 )
{

try {

iCount ++;
out.print( j + “Closing: ” + oItemTest[j].getPath() + “,” + oItemTest[j].getFullName() + “,” + aFields[i] + “n” + “<br>”);

}
catch ( Exception e ) {out.print(“no”); }

}
}
}

}

}[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@harrierdhJan 19.2010 — Looks like Java or JSP. This is a Javascript forum. Completely different languages. If you wanted to find all the div tags in Javascript (client side). It would look like this.

<script>

var myDivTags = document.getElementsByTagName("DIV");

alert(myDivTags.length);

</script>

Otherwise post to the correct forum.
×

Success!

Help @AR123 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...