0

Need to dynamicaly cha data attribute change h3 text using

$('.partOfMachine').hover(function(){
  $(this).addClass('thisPart');
  var nPart = $(this).data('namePart');
  $('#textPart').text(nPart);
 }, function(){
  $(this).removeClass('thisPart');
  $('#textPart').text('Модель состовляющих завода');
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="machinery">
    <h3 class="text-center" id="textPart">Модель состовляющих завода</h3>
    <a href="recycling.php"><div class="partOfMachine" id="recyclingPart" data-namePart="Переработка"></div></a>
    <a href="cutting.php"><div class="partOfMachine" id="cuttingPart" data-namePart="Резка"></div></a>
    <a href="aging.php"><div class="partOfMachine" id="firstAgingPart" data-namePart="Выдержка сырья"></div></a>
    <a href="moulding.php"><div class="partOfMachine" id="blockMouldingPart" data-namePart="Блок-формовочное оборудование"></div></a>
    <a href="expanding.php"><div class="partOfMachine" id="expandingPart" data-namePart="Предвспениватели"></div></a>
    <a href="aging.php"><div class="partOfMachine" id="secondAgingPart" data-namePart="Выдержка сырья"></div></a>
    <a href="moulding.php"><div class="partOfMachine" id="shapeMouldingPart" data-namePart="Фигурно-формовочное оборудование"></div></a>
</div>

Need to dynamicaly cha data attribute change h3 text using

2 Answers2

0

use var nPart = $(this).attr('data-namePart'); or make the attribute name lowercase data-namepart, then $(this).data('namepart') will work

Pavel Gatnar
  • 3,987
  • 2
  • 19
  • 29
0

You can also get the html attribute value with jquerys .attr() function like so :

var nPart = $(this).attr('data-namePart')