Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a tag like:

HTML
<h3 >Mobile<img src="/Images/edit.png" alt="Edit" align="middle" class="attEditCategory" /><img src="/Images/delete.png" alt="Delete" align="middle" class="attDeleteCategory" /></h3>


I want to display the text of h3 ie "Mobile" in edit click button (on alert).


JavaScript
$(".attEditCategory").button().on("click", function (event) {
                        
});


Please help.
Posted
Comments
Sinisa Hajnal 3-Nov-14 6:45am    
What have you tried? Why is this a problem?
ujju.1 3-Nov-14 6:50am    
i have tried alert($(this).html()); or alert($(this).closest('h3').html()); but no use.

JavaScript
alert($(this).parent().text());


working fine :)
 
Share this answer
 
You're writing wrong code, write this

JavaScript
$('button').click(function () {
   // add text
   $('h3 span').text('Mobile');
});


This means that in the beginning, you're going to remove any text from the h3.

HTML
<h3>
  <span></span>
  <img src="/Images/edit.png" alt="Edit" align="middle" class="attEditCategory" />
  <img src="/Images/delete.png" alt="Delete" align="middle" class="attDeleteCategory" /></h3>


You need to have a span element atleast in the h3 element just to ensure that upon the code execution the images don't get removed when you add text to it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900