event.trigger is not working only in the following case.

js file:

alert(event.target.getAttribute("name"));

html file:

            <div class=" tile  tile-big tile-5" id="three" name = "Launch" >
                <div><p>Launch Application </p></div>
            </div>

it is giving "null", not name.

and alert(document.getElementById(this.id).getAttribute("name")); is working fine.

help me.

Thanks in advance.

有帮助吗?

解决方案

the problem is your target is not

<div class=" tile  tile-big tile-5" id="three" name = "Launch" >

but

<p>Launch Application </p>

which does not have "name" attribute that is why you get null try to add name attribute to it and you will get right alert.

try this

<div class=" tile  tile-big tile-5" id="three" name = "Launch" onclick="testAlert(event)">
            <div name = "Launch2"><p name = "Launch3">Launch Application </p></div>
</div>

<script>
function testAlert(event) 
{
    var target = event.target || event.srcElement;
    alert(target.getAttribute('name'));
}
</script>

you will get the answer

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top