मैं सामग्री के साथ contenteditable div
मिल गया है प्राप्त करें:जावास्क्रिप्ट - contenteditable div में पत्र जो पहले कैरट (कर्सर) है की सीएसएस शैली
<span style="font-weight: 700">S</span>
<span style="font-weight: 100">o</span>
<span style="color: red">m</span>
<span style="text-decoration: underline">e</span>
<span style="background-color: green">T</span>
<span style="text-decoration: line-through">e</span>
<span style="font-style: italic">x</span>
<span style="font-family: Arial">t</span>
और मैं तत्व है जो पहले कैरट (कर्सर) है की शैली प्राप्त करना चाहते हैं । उदाहरण के लिए यदि मुझे Some
और Text
के बीच परवाह है तो मैं text-decoration: underline
प्राप्त करना चाहता हूं। मेरा कोड नीचे है (काम कर रहा है, लेकिन मुझे अंतिम तत्व की शैली मिलती है (font-family: Arial
))। जावास्क्रिप्ट या/और JQuery का उपयोग करके, मैं इसे कैसे ठीक कर सकता हूं?
सहायता के लिए धन्यवाद।
$('button').click(function() {
var style = $('#Box span').last().attr('style');
$('#Result').text('Result: ' + style);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="Box" contenteditable="true">
<span style="font-weight: 700">S</span><span style="font-weight: 100">o</span><span style="color: red">m</span><span style="text-decoration: underline">e</span><span style="background-color: green">T</span><span style="text-decoration: line-through">e</span><span style="font-style: italic">x</span><span style="font-family: Arial">t</span>
</div>
<button>Get result</button>
<p id="Result"></p>
अच्छा अच्छा परिणाम के लिए प्रयास –