Timo
Timo

Reputation: 35

DOM get name element by input id

My html code looks like this

<input type="text" class="bk-i bk-fill-parent" id="loginField" name="loginSGizS" autocomplete="off" maxlength="20">

I want to get what's inside name=" " which is loginSGizS, now I see the obvious way is by input id, but I can't quite figure it out

UPDATE: I'm using this inside a php file with curl and I kind of need to keep everything within that file. What I tried so far

<?php       $home = curl('https://website.com'); $oDom = new simple_html_dom(); $oDom->load($home); $elements = $oDom->getElementById("loginField"); foreach($elements as $element){ echo $element->getAttribute('name'); }

UPDATE: I used regex $pattern = '/<input (?=[^>]* id="loginField" name=["]([^"]*)|)/ms'; and it works, thank y'all

Upvotes: 0

Views: 199

Answers (2)

Shahnewaz
Shahnewaz

Reputation: 360

You can easily get it by attr method:

var name = $("#id").attr("name");

Upvotes: 0

M. Duisenbayev
M. Duisenbayev

Reputation: 319

document.getElementById("loginField").getAttribute("name")

Upvotes: 1

Related Questions