Someone
Someone

Reputation: 10575

How to get the value of JavaScript Object

this.mobj=document.getElementById(menu1)
var ob1 = this.mobj;
alert(" Obj value"+ob1.whichmethod());

In the alert I am getting "Drop menu Obj"+Object object This is JavaScript.. If it was jQuery I could have done $(this).attr('value'). How to get the value of JavaScript object?

Upvotes: 1

Views: 8932

Answers (3)

Ravindra Miyani
Ravindra Miyani

Reputation: 370

you can access the object properties by dot operator(.) or Square brackets([]).

For Example.

var pair = new Object();
 pair[0] = "value One"
 pair[1] = "value Two"
 pair[2] = "value Three"
 pair[3] = "value Four"
 pair["Five"] = "value Five"

you can use **pair.Five** or pair["Five"]

Upvotes: 0

James Johnson
James Johnson

Reputation: 46047

I'm not sure if you're looking for more, but if you want the value property of the object in JavaScript, you can do it like this:

mobj = document.getElementById(menu1);
if (mobj){
    var obj_value = mobj.innerText; //or innerHTML;
}

If you're looking for the href of the hyperlink, you can get it like this:

mobj = document.getElementById(menu1);
if (mobj){
    var obj_value = mobj.href;
}

Upvotes: 2

Ivan Nikolchov
Ivan Nikolchov

Reputation: 1574

document.getElementById(menu1).value or ob1.value

Upvotes: 2

Related Questions