Onclick pass element class in javascript

I wrote code like this

<?php
$extCount = 0;
foreach($this->externalReferal as $externalReferal)
{
$extCount++;
?>

    <div class='fieldtestPct' >
      <div class='fieldItemLabel'>
                <label for=''><?php echo $externalReferal->getConsultantname(); ?> ( <?php echo $externalReferal->getSpeciality(); ?> )</label>
      </div>
        <div class='fieldItemValue'>
                <input type='checkbox' class='ext_ref_list<?php echo $extCount; ?>' name='ext_ref_cons[]' value="Consultant<?php echo $extCount ?>" >
         </div>
    </div>

<div class='fieldtestPct'>
      <div class='fieldItemLabel'>
                <label for=''>Current Visit</label>
      </div>
        <div class='fieldItemValue'>
                <input type='checkbox' class='current_visit<?php echo $extCount; ?>' name='current_visit[]' value="" onClick ='currentVisit(this.class)'>
         </div>
    </div>
<div class='fieldtestPct'>
      <div class='fieldItemLabel'>
                <label for=''>Full Data</label>
      </div>
        <div class='fieldItemValue'>
                <input type='checkbox' class='full_data<?php echo $extCount; ?>' name='full_data[]' value="" onClick='fullData(this)'>
         </div>
    </div>

                <div class='clear'></div>
<?php
}
?>

Here I need to do a dynamic action when clicking the checkboxes. how to pass the selected class / element data to javascipt.

+3
source share
1 answer

Use this.classNameinstead this.class.

The class nameName is used for this property instead of the class due to conflicts with the "class" keyword in many languages ​​that are used to control the DOM.

https://developer.mozilla.org/en/DOM/element.classname

+3
source

Source: https://habr.com/ru/post/1757299/


All Articles