Does anyone knows how to select dynamic classes using jquery@

Im trying to select in h3 classes when the tab is generated a page. any ideas anyone?

// random dynamic classes for Job Description heading title
$rand = rand(1,50);
$jd = ‘jd-’;
$jd .= $rand;

// random dynamic classes for main content
$rands = rand(50,100);
$maintitlesjd = ‘maintitles_jd-’;
$maintitlesjd .= $rands;

echo(“<h3 class=‘$jd toggle’>” . ‘Job Description’ . ‘</h3>’);

Should be possible and there are a number of options, but I’ll be able to help more if you can post some HTML (i.e. whatever is generated by your PHP script)

Here are the code im using:

<?php

// random dynamic classes for Job Description heading title
$rand = rand(1,50);
$jd = ‘jd-’;
$jd .= $rand;

// random dynamic classes for main content
$rands = rand(50,100);
$maintitlesjd = ‘maintitles_jd-’;
$maintitlesjd .= $rands;

			require_once("../php_engine/_php_xml.php");
			
			if(isset($_POST["qsurvey"]) && isset($_POST["qjobnumber"])){
				$x = new aj_xml($_POST["qsurvey"],$_POST["qjobnumber"]);
			}else{
				$x = new aj_xml('LOCL','10.02',true);
			}
			
			if($x-&gt;file_does_exist == true){
				
					echo("&lt;div id='dad'&gt;");
						echo("&lt;h3 class='$jd toggle'&gt;" . 'Job Description' . '&lt;/h3&gt;');
						
						echo("&lt;div class='$maintitlesjd maintitles_jd' id='jd_content'&gt;");
						
						$x-&gt;readxml_jd();
							
						if(isset($x-&gt;values)){
						 	foreach($x-&gt;values as $key=&gt;$value){
									if($value!='')
									{
										if(is_numeric($key)) echo "&lt;p class='lines'&gt;" . $value . "&lt;/p&gt;";
										if(!is_numeric($key))echo "&lt;div class='lines'&gt;&lt;span class='heading_jd'&gt;" . $key. "&lt;/span&gt;" . $value . "&lt;/div&gt;";
									}
								}
						}	
							
					echo("&lt;/div&gt;"); // end of jd_content DIV
					echo("&lt;/div&gt;");// end of dada DIV		
				}	

?>

<div class=“dad”>
<h3 class=“jd-11 toggle”>Job Description</h3>
<div class=“maintitles_jd-87 maintitles_jd” id=“jd_content”>
<div class=“lines”><span class=“heading_jd”>SURVEY JOB NUMBER</span>10.01</div>
<div class=“lines”><span class=“heading_jd”>SURVEY JOB TITLE</span> GENERAL MANAGER</div>
<div class=“lines”><span class=“heading_jd”>ALTERNATIVE TITLE</span>Managing Director</div>
<div class=“lines”><span class=“heading_jd”>JOB PURPOSE</span>Responsible for running the UK diagnostic company/division. To be responsible for providing strategic direction to the UK business. To plan for and to ensure the achievement of targeted sales revenue and profit and growth plans for the company. </div>
<div class=“lines”><span class=“heading_jd”>TYPICAL RESPONSIBILITIES</span> </div>
<p class=“lines”>To be a Director of the UK company</p>
<p class=“lines”>To have full P&L responsibility for the business</p>
<p class=“lines”>To plan and implement the growth objectives for the company</p>
<p class=“lines”>To ensure the senior management team are fully supported and aware of their own and their teams’ objectives</p>
<p class=“lines”>To work closely with the management team in achieving the company objectives, planning, budgeting </p>
<p class=“lines”>To ensure appropriate staff training and development for all members of staff</p>
<p class=“lines”>To set appropriate targets and rewards for staff</p>
<p class=“lines”>To ensure implementation of competitive pricing policy for all products to maximise sales and to achieve the Business plan</p>
<p class=“lines”>To identify any possible new business opportunities that may complement company portfolio</p>
<p class=“lines”>To ensure UK company compliance to group company objectives, e.g. continuous improvement </p>
<p class=“lines”>To maintain the Health & Safety policy for the Company</p>
<div class=“lines”><span class=“heading_jd”>EDUCATION, SKILLS & EXPERIENCE</span> </div>
<p class=“lines”>Graduate level education</p>
<p class=“lines”>Post-graduate business qualification</p>
<p class=“lines”>In depth knowledge of the relevant markets </p>
<p class=“lines”>Proven ability to manage a profitable business</p>
</div>
</div>

Hi there,

Presuming all of the <h3> tags you want to select have ids starting with “jd-”, this sounds like a job for the attribute starts with selector.

So, in your case, this would be:

$('h3[class^="jd-"]')

A further example:

<!DOCTYPE HTML>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Unbenanntes Dokument</title>
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
  </head>
  <body>
    <h3 class="jd-10 toggle">Job Description 1</h3>
    <h3 class="jd-11 toggle">Job Description 2</h3>
    <h3 class="jd-12 toggle">Job Description 3</h3>
    <h3 class="jd-13 toggle">Job Description 4</h3>
    <h3 class="jd-14 toggle">Job Description 5</h3>

    <script>
      $(document).ready(function() {
        $headings = $('h3[class^="jd-"]')
        console.log($headings.length);
      });
    </script>
  </body>
</html>

HTH

Do you know how to create toggle div img plus and minus when click on that heading?

I’ve been trying to use this code below but it doesnt work properly.

$(“.dad h3”).click(function(event){
//event.stopPropagation();

$(this).next(".dad .maintitles_jd").stop(true, true).slideToggle()
 .siblings(".dad .maintitles_jd:visible").stop(true, true).slideUp();
				
$(this).stop(true, true).toggleClass("active");
$(this).siblings(".dad h3").removeClass("active");

});

the first toggle when clicked worked correctly but when clicked on the second one it keeps toggle up and down.

I’m probably missing something, but this works for me:

$(".dad h3").click(function(){
  $(this).next().slideToggle();
});

Could you post a link to a page where I could see this in action?

Here’s a standard tree-view plugin for jQuery, that is very successful at doing what it does.

it works ok on first toggle but when clicked on the other ones it just keep toggle up and down repeatedly :confused:

joeboo: Could you post a link to your site?

There’s also a slightly older tree-view that uses plus and minus signs on each branch, at https://github.com/jzaefferer/jquery-treeview

sorry Pullo i cant as we running as internal web server for our company see.

Okay then. Please let us when there’s a way for us to experience the same problem that is being experienced there.
We will then be able to more easily provide you with assistance for the issue.

As Paul says, we need to really see the problem to be able to help further.

The only other thing which might work is if you go to the page where you are having the trouble, inspect the source code of the page (e.g. Ctrl + U in Chrome), then paste the source code here.
If you do that, please be sure to use code tags.

thanks for the help guys but I’ve managed to fix it now :slight_smile: