2016-09-17 2 views
0

나는 outerHTML에서 얻은 문자열을 가지고 있습니다. values["hello"] => "world"jquery를 사용하여 html에서 속성 추출하기

내가 여기에 붙어 : 나는 그래서 내가 좋아하는 '세계'를 액세스 할 수있는 형식으로 그걸 얻기 위해 노력하고

var responseHtml = jQuery(data).find("#response")[0].outerHTML; 
console.log(responseHtml); 

Log: 

<div id="response" hello="world" big="span" hey="there">&lt;\/div&gt;" 
<div class="clear"></div></div> 

: 것처럼 기록합니다. 그것을 성취하기위한 적절한 방법은 무엇입니까? jQuery로 그 값을 얻으려면 다음

<div id="response" data-hello="world" data-big="span" data-hey="there"></div> 

그리고, 당신이 할 수 있습니다 :

+0

첫째, 모든 속성은 유효하지 않습니다. 데이터 속성을 사용해야합니다. 둘째,'$ ('#'response ')와 같이 간단하게 접근해야한다. – adeneo

+1

'$ ('# response '). attr ('hello ')' –

+0

고마워요 !!! – senty

답변

0

오히려 잘못된 속성을 만드는 대신, 당신은 data 속성처럼 사용한다

var response = $('#response'); 
response.data('hello'); // returns "world" 
response.data('big'); // returns "span" 
response.data('hey'); // returns "there" 

JS Fiddle

관련 문제