jQuery find id, that's inside data-target attr
up vote
-2
down vote
favorite
I'm trying to get the id, that's inside a data target.
For structure, i mean like this
PARENT (DATA TARGET)
|
V
CHILD (ID)
Hope that makes a more clear vision
I've tried the following code here.:
jQuery(document).ready(function($) {
$("a.print").click(function(event) {
var id = $(this).attr("data-target").find("#edit_cookie"); // Look for the id inside data-target
alert($(id));
});
});
But all it gives is this
Uncaught TypeError: $(...).attr(...).find is not a function
JSFIDDLE:
http://jsfiddle.net/4pa3hqgt/2/
What can i do here?
Kind regards
javascript jquery html
add a comment |
up vote
-2
down vote
favorite
I'm trying to get the id, that's inside a data target.
For structure, i mean like this
PARENT (DATA TARGET)
|
V
CHILD (ID)
Hope that makes a more clear vision
I've tried the following code here.:
jQuery(document).ready(function($) {
$("a.print").click(function(event) {
var id = $(this).attr("data-target").find("#edit_cookie"); // Look for the id inside data-target
alert($(id));
});
});
But all it gives is this
Uncaught TypeError: $(...).attr(...).find is not a function
JSFIDDLE:
http://jsfiddle.net/4pa3hqgt/2/
What can i do here?
Kind regards
javascript jquery html
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I'm trying to get the id, that's inside a data target.
For structure, i mean like this
PARENT (DATA TARGET)
|
V
CHILD (ID)
Hope that makes a more clear vision
I've tried the following code here.:
jQuery(document).ready(function($) {
$("a.print").click(function(event) {
var id = $(this).attr("data-target").find("#edit_cookie"); // Look for the id inside data-target
alert($(id));
});
});
But all it gives is this
Uncaught TypeError: $(...).attr(...).find is not a function
JSFIDDLE:
http://jsfiddle.net/4pa3hqgt/2/
What can i do here?
Kind regards
javascript jquery html
I'm trying to get the id, that's inside a data target.
For structure, i mean like this
PARENT (DATA TARGET)
|
V
CHILD (ID)
Hope that makes a more clear vision
I've tried the following code here.:
jQuery(document).ready(function($) {
$("a.print").click(function(event) {
var id = $(this).attr("data-target").find("#edit_cookie"); // Look for the id inside data-target
alert($(id));
});
});
But all it gives is this
Uncaught TypeError: $(...).attr(...).find is not a function
JSFIDDLE:
http://jsfiddle.net/4pa3hqgt/2/
What can i do here?
Kind regards
javascript jquery html
javascript jquery html
edited Nov 8 at 13:26
asked Nov 8 at 12:58
Aske Lexo
23
23
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30
add a comment |
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I assume you want to find the parent and then choose its child and read ID from there.
First you select the parent. Then access children and use some selector to get the one you want and there you get the id attribute. So it should look something like this:
edit to work with your html:
$(document).ready(function () {
$('a.print').on("click", function () {
var id = $('div[data-target="customized"]>div').attr('id');
alert(id);
});
});
working example in comments bellow
alert($(id));
would always produce"[object Object]"
– charlietfl
Nov 8 at 13:14
you are right, I concentrated just on the first part of the code :-) to print out the value its just alert(id);
– MrChikns
Nov 8 at 13:15
Hey, thanks! :-) I've added an JSFiddle to the post :-)
– Aske Lexo
Nov 8 at 13:20
I used plnkr to edit it and there it is working. plnkr.co/edit/xqnoV8f12TAlY59RM678?p=preview
– MrChikns
Nov 8 at 13:56
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I assume you want to find the parent and then choose its child and read ID from there.
First you select the parent. Then access children and use some selector to get the one you want and there you get the id attribute. So it should look something like this:
edit to work with your html:
$(document).ready(function () {
$('a.print').on("click", function () {
var id = $('div[data-target="customized"]>div').attr('id');
alert(id);
});
});
working example in comments bellow
alert($(id));
would always produce"[object Object]"
– charlietfl
Nov 8 at 13:14
you are right, I concentrated just on the first part of the code :-) to print out the value its just alert(id);
– MrChikns
Nov 8 at 13:15
Hey, thanks! :-) I've added an JSFiddle to the post :-)
– Aske Lexo
Nov 8 at 13:20
I used plnkr to edit it and there it is working. plnkr.co/edit/xqnoV8f12TAlY59RM678?p=preview
– MrChikns
Nov 8 at 13:56
add a comment |
up vote
0
down vote
I assume you want to find the parent and then choose its child and read ID from there.
First you select the parent. Then access children and use some selector to get the one you want and there you get the id attribute. So it should look something like this:
edit to work with your html:
$(document).ready(function () {
$('a.print').on("click", function () {
var id = $('div[data-target="customized"]>div').attr('id');
alert(id);
});
});
working example in comments bellow
alert($(id));
would always produce"[object Object]"
– charlietfl
Nov 8 at 13:14
you are right, I concentrated just on the first part of the code :-) to print out the value its just alert(id);
– MrChikns
Nov 8 at 13:15
Hey, thanks! :-) I've added an JSFiddle to the post :-)
– Aske Lexo
Nov 8 at 13:20
I used plnkr to edit it and there it is working. plnkr.co/edit/xqnoV8f12TAlY59RM678?p=preview
– MrChikns
Nov 8 at 13:56
add a comment |
up vote
0
down vote
up vote
0
down vote
I assume you want to find the parent and then choose its child and read ID from there.
First you select the parent. Then access children and use some selector to get the one you want and there you get the id attribute. So it should look something like this:
edit to work with your html:
$(document).ready(function () {
$('a.print').on("click", function () {
var id = $('div[data-target="customized"]>div').attr('id');
alert(id);
});
});
working example in comments bellow
I assume you want to find the parent and then choose its child and read ID from there.
First you select the parent. Then access children and use some selector to get the one you want and there you get the id attribute. So it should look something like this:
edit to work with your html:
$(document).ready(function () {
$('a.print').on("click", function () {
var id = $('div[data-target="customized"]>div').attr('id');
alert(id);
});
});
working example in comments bellow
edited Nov 8 at 14:02
answered Nov 8 at 13:12
MrChikns
464
464
alert($(id));
would always produce"[object Object]"
– charlietfl
Nov 8 at 13:14
you are right, I concentrated just on the first part of the code :-) to print out the value its just alert(id);
– MrChikns
Nov 8 at 13:15
Hey, thanks! :-) I've added an JSFiddle to the post :-)
– Aske Lexo
Nov 8 at 13:20
I used plnkr to edit it and there it is working. plnkr.co/edit/xqnoV8f12TAlY59RM678?p=preview
– MrChikns
Nov 8 at 13:56
add a comment |
alert($(id));
would always produce"[object Object]"
– charlietfl
Nov 8 at 13:14
you are right, I concentrated just on the first part of the code :-) to print out the value its just alert(id);
– MrChikns
Nov 8 at 13:15
Hey, thanks! :-) I've added an JSFiddle to the post :-)
– Aske Lexo
Nov 8 at 13:20
I used plnkr to edit it and there it is working. plnkr.co/edit/xqnoV8f12TAlY59RM678?p=preview
– MrChikns
Nov 8 at 13:56
alert($(id));
would always produce "[object Object]"
– charlietfl
Nov 8 at 13:14
alert($(id));
would always produce "[object Object]"
– charlietfl
Nov 8 at 13:14
you are right, I concentrated just on the first part of the code :-) to print out the value its just alert(id);
– MrChikns
Nov 8 at 13:15
you are right, I concentrated just on the first part of the code :-) to print out the value its just alert(id);
– MrChikns
Nov 8 at 13:15
Hey, thanks! :-) I've added an JSFiddle to the post :-)
– Aske Lexo
Nov 8 at 13:20
Hey, thanks! :-) I've added an JSFiddle to the post :-)
– Aske Lexo
Nov 8 at 13:20
I used plnkr to edit it and there it is working. plnkr.co/edit/xqnoV8f12TAlY59RM678?p=preview
– MrChikns
Nov 8 at 13:56
I used plnkr to edit it and there it is working. plnkr.co/edit/xqnoV8f12TAlY59RM678?p=preview
– MrChikns
Nov 8 at 13:56
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208245%2fjquery-find-id-thats-inside-data-target-attr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30