• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 88
  • Last Modified:

javascript to set the parents css selector on a click event

javascript to set the parents css selector on a click event
0
cbrune
Asked:
cbrune
  • 2
1 Solution
 
Greg AlexanderLead DeveloperCommented:
In pure javascript I think this would do it:

<script>
function change_class(ele){
	d = ele.parentNode;
	d.className = d.className + " another_class";
}
</script>

<div class="one_class">
	<div id="element" onClick="change_class(this)">Content</div>
</div>

Open in new window

0
 
Greg AlexanderLead DeveloperCommented:
A jquery verion:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<div class="one_class">
	<div id="element" onClick="$(this).parent().addClass('another_class');">Content</div>
</div>

Open in new window

0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now