0

Here the html code

<span class="setcategory2">
   <img src="/images/dotes/travel.png">
TRAVEL
</span>

How can i get value of TRAVEL which is after img tag

oxygen
  • 81
  • 8

2 Answers2

2

$(function() {
  var imgText = $('span.setcategory2').text(); //to get the text after img

  $('div').text("The image text is: "+ imgText);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="setcategory2">
   <img src="/images/dotes/travel.png">
TRAVEL
</span>

<div>
 
</div>
Rajshekar Reddy
  • 18,647
  • 3
  • 40
  • 59
0

You can assign it to a variable like this...

var name = $('span').text();

Or if it was a specific span with an ID then...

var name = $("#idofspan").text();
Rob
  • 738
  • 3
  • 10
  • 23