-8

I want to change the parent class on click

My HTML code

<div class="banner">
      <input type="submit" value="Submit" class="submit"/>
 </div>

My Script

  $(".submit").click( function (){
     $(this).toggleClass("banner expand_it");
  });
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • 4
    Come on, you haven't even tried... – Niet the Dark Absol Nov 20 '16 at 10:30
  • 1
    Your code is jQuery. I added the tag. Now please search google or SO for _jquery toggle parent class_ – mplungjan Nov 20 '16 at 10:33
  • Please visit the [help] to see how and what to ask. HINT: Post code and effort - as you can see the members of SO does not take kindly to questions without any effort shown – mplungjan Nov 20 '16 at 10:35
  • Your event is attached to the submit button so when you use `$(this)` as a selector you are targeting the element use to trigger that event. so that would mean you are running `.toggleClass()` on the submit button and nothing else. Just like in your question you want to target the parent and I see of no attempt to find or target the parent element. I believe your real problem is due to lack of research. – NewToJS Nov 20 '16 at 10:35
  • sorry guys, I have tried it I have searched also but still not get the result. I know its a simple task for expert. – Sultan khan Nov 20 '16 at 11:39
  • Not for expert. Searching "get parent jquery", and the first result on Google is what you are looking for – Hellium Nov 20 '16 at 12:34
  • Possible duplicate of [Toggle show/hide on click with jQuery](http://stackoverflow.com/questions/10310717/toggle-show-hide-on-click-with-jquery) – A1raa Nov 20 '16 at 13:07

1 Answers1

2

JQuery has a parent function to get the parent of a given element

https://api.jquery.com/parent/

$(".submit").click( function (){
    $(this).parent().toggleClass("banner expand_it");
});
Hellium
  • 7,206
  • 2
  • 19
  • 49