Khant Thu Linn
Khant Thu Linn

Reputation: 6133

Write javascript to detect click event in li

I have li something like this.This code is from some website and I don't have permission to modify that code.

<li class="History_lisitem_logout ui-last-child" data-icon="power">
                        <a id="History_lisitem_logout" name="lisitem_logout" dsid="lisitem_logout" tabindex="2" class="History_lisitem_logout ui-btn ui-btn-icon-right ui-icon-power">
                        <h3>Sign Out</h3>
                        </a>
                    </li>

I need to call that website from my ios or android app and if user click on that li, i need to trigger my own native code.

If it is normal button, I can easily do like this to call my native code.

        webView.stringByEvaluatingJavaScript(from: "$(document).on('touchstart', '#History_lisitem_logout', function() {window.location = 'ios:logoutGleer';});")

However, the issue is that I don't have 'id' in 'li' and I cannot inject my javascript code to detect event for clicking 'li'. How shall I do?

Upvotes: 0

Views: 149

Answers (1)

Rajkumar Somasundaram
Rajkumar Somasundaram

Reputation: 1270

Anchor tag has id; make use of it.

let listEl = document.getElementById("History_lisitem_logout").parentElement

Upvotes: 1

Related Questions